Google Maps API V2
1. 在AndroidManifest.xml的application节点中,添加Google play service的版本号:
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
2. 申请API Key,添加到AndroidManifest.xml的application节点中:
<meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="API_KEY"/>
3. 添加所需的uses-permission:
<uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/> <!-- The following two permissions are not required to use Google Maps Android API v2, but are recommended. --> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
4. 添加OpenGL ES2的申明:
<uses-feature android:glEsVersion="0x00020000" android:required="true"/>
5. 现在可以在代码中添加地图了,如MapFragment,一般是定义在布局文件,包含在Activity中:
<?xml version="1.0" encoding="utf-8"?> <fragment xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/map" android:layout_width="match_parent" android:layout_height="match_parent" android:name="com.google.android.gms.maps.MapFragment"/>