Google Maps API v2 Demo Tutorial
申请API KEY
https://code.google.com/apis/console/?noredirect
1. 创建项目,名称随意,只是为了区分
2. 开启Google Maps Android API v2服务
3. 申请API KEY,使用证书的SHA1值和package name
注:Create an OAuth 2.0 client ID...这个东西不用去管它
设置Google Play Service
1. 使用Android包管理下载,Extras->Google Play Service
2. 同时下载对应Android版本的Google APIs
3. 导入Google_Play_Serviecs_Lib,勾选Copy Projects into Workspace,路径是<android-sdk>/extras/google/google_play_services/libproject/google-play-services_lib/
参考:http://developer.android.com/google/play-services/setup.html
创建新的App Project
1. 创建Android Application Project,Compile With不需要选择Google APIs也可以
2. 引用Google_Play_Services_Lib,Project->Properties->Android,新增引用
3. 在AndroidManifest.xml中增加Google Play services version
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
4. 在AndroidManifest.xml中增加API Key
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="API_KEY"/>
5. 在AndroidManifest.xml中增加Permissions
<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"/>
6. 在AndroidManifest.xml中增加OpenGL ES version 2
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
7. 在activity-main.xml中增加Map的Fragment
8. MainActivity.java的代码不用做修改
参考:https://developers.google.com/maps/documentation/android/start?hl=zh-cN