如何使用Google Map API开发Android地图应用

两年前开发过的GoogleMap已经大变样,最近有项目要用到GoogleMap,重新来配置Android GoogleMap开发环境,还真是踩了不少坑。

一、下载Android SDK Manager(& Proxy Setting)

此小节详见 Android开发环境搭建之AndroidStudio

 

二、安装Google Play Services SDK、Google APIs Platform(19)

由于SDK下载需要FQ,因此需要配置代理镜像[http://www.androiddevtools.cn/ (腾讯Bugly 镜像)]

开发Google的相关功能需要下载集成了Google APIs的SDK Platform; 另外Google Map SDK集成在Google Play Services SDK中,因此需要安装。

 

三、申请Google Map API key(Android)

申请方法有两种,前提是拥有Google Account,并注册Google AppEngine

其一是用AndroidStudio创建一个GoogleMap项目(Android项目包名: com.s3graphics),根据生成的google_maps_api.xml文件中提供的APIKey申请链接跳转到Google AppEngine;根据提示创建一个GAE google-map项目,完成后即可生成AndroidKey。注:APIKey申请链接中包含了SHA1和Android项目包名。

其二是在Google Projects创建一个GAE google-map项目,然后在该项目中添加一个AndroidKey;再用keytool工具在本地生成SHA1后,将SHA1与Android项目包名添加到AndroidKey中。

两种申请方法一致,只是第一种是由AndroidStudio生成SHA1和申请链接,简化AndroidKey申请过程。

申请到API Key后将AndroidKey中的key值添加到AndroidStudio google_maps_api.xml文件中,即可进行开发。

下面用图来描述第二种申请Key的具体过程。

1.进入Google Projects,并创建google-map项目

2.为google-map项目添加AndroidKey

3.使用keytool根据Android debug.keystore生成SHA1信息

4.将包名和SHA1信息添加到AndroidKey中

 

四、Genymotion安装Google Services

由于AVD运行速度慢,推荐使用Genymotion+Google Services。因为Genymotion不包含Google Services,需要手动安装补丁包。

1.Genymotion-ARM-Translation_v1.1.zip 下载

2.gapps-lp-20141109-signed.zip(for Android 4.4) 下载

安装方法:如果链接无法打开请使用goagent-crack代理(具体教程可查看Go-Agent部署与FQ)。

adb push Genymotion-ARM-Translation_v1.1.zip /sdcard/Download/
adb push gapps-lp-20141109-signed.zip /sdcard/Download/
adb shell "/system/bin/flash-archive.sh /sdcard/Download/Genymotion-ARM-Translation_v1.1.zip"
adb shell "/system/bin/flash-archive.sh /sdcard/Download/gapps-lp-20141109-signed.zip"
adb reboot

3.安装完成上述两个包后,需要使用Google Account更新Genymotion中Google相关软件,如Google PlayStore/Google Maps

注意:更新过程中可能遇到的网络问题。

1.更新需要连接外网,可使用Charles+Go-Agent代理实现。

大致原理如下:Genymotion网络走PC Charles,Charles网络走Go-Agent。

(尝试过Genymotion直接设置Go-Agent代理,但由于Gemymotion内Go-Agent证书问题失败)

开启Charles代理,默认端口8888

开启Charles外部代理,使用GoAgent代理(127.0.0.1:8087),用于解决外网访问问题

Genymotion配置Charles代理(10.0.3.2:8888)

(图中8087为Go-Agent端口,不采用该方式;10.0.3.2是Genymotion中代表PC的IP)

安装Charles证书

(配置好代理IP和端口号后,在浏览器中访问http://www.charlesproxy.com/getssl)

2.需要调整模拟器时间设置,关闭自动更新,并选择正确的时区和时间,否则出现连接错误。

五、编写Android Map应用并运行

经过曲折的GoogleMap Services的安装,Genymotion中Google APIs 的安装,终于可以如愿以偿的开发Google Maps应用了。

不过后面仍然面对真机无法安装Google APIs的问题,主要是针对没有root权限导致。

 

参考链接:

[SDK Manager] http://developer.android.com/tools/help/sdk-manager.html

[Google APIs] https://console.developers.google.com/apis/library?project=git-blog&hl=en-US

[注册和 API 密钥] https://developers.google.com/maps/documentation/android-api/signup#release-cert

[hellomap-android] https://github.com/googlemaps/hellomap-android

[Google Maps Android API 入门指南]

https://developers.google.com/maps/documentation/android-api/start

[Get Started with Premium Plan on Android]

https://developers.google.com/maps/premium/android-get-started#overview

[Genymotion with Google APIs] https://inthecheesefactory.com/blog/how-to-install-google-services-on-genymotion/en

[Failed to flash file] https://gist.github.com/wbroek/9321145

[Install Google Services on Genymotion] 

https://inthecheesefactory.com/blog/how-to-install-google-services-on-genymotion/en

https://guides.codepath.com/android/Genymotion-2.0-Emulators-with-Google-Play-support

[Fix No Connection – Retry error message on Google Play Store App] (FIX DATE AND TIME SETTINGS)

http://wccftech.com/fix-no-connection-retry-error-message-on-google-play-store-app/

http://www.techkhoji.com/no-connection-retry-google-play-store/ 

 

posted @ 2016-05-06 22:53  tesky0125  阅读(2005)  评论(0编辑  收藏  举报