- Start a new project named HelloAndroidcodeplusMaps.
- Because the Maps library is not a part of the standard Android library, you must
declare it in the Android Manifest. Open the
AndroidManifest.xml
file and add the following as a child of the <application>
element:
- <uses-library android:name="com.google.android.maps"/>
- You also need access to the Internet in order to retrieve map tiles,
so you must also request the
INTERNET
permission.
In the manifest file, add the following as a child of the <manifest>
element:
<uses-permission android:name="android.permission.INTERNET" />
- While you're in the manifest, give the map some more space by getting rid of the title bar
with the "NoTitleBar" theme:
<activity android:name=".HelloAndroidcodeplusMap"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar">
- Open the
res/layout/main.xml
file and add a single
com.google.android.maps.MapView
as the root node:
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.maps.MapView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"
android:apiKey="Your Maps API Key goes here"
/>
The android:clickable
attribute defines whether you want to allow
user-interaction with the map. If this is "false" then touching the map does nothing.
No comments :
Post a Comment