SlideShare una empresa de Scribd logo
1 de 34
Descargar para leer sin conexión
Google Map #1
根據Google Maps Android API
V2更新
曾吉弘
nissin@cavedu.com
1
大綱
• Google Maps Android API V2
• 申請Google Map API Key
• 載入Google Map - GMap
2
環境建置
Google Maps Android API V2
3
步驟
1. 安裝 Google Play services SDK
2. 取得SHA1 憑證
3. Google APIs Console取得API key
4. 設定權限
5. 加入地圖
4
V1 / V2比一比
• V1 的專案版本一定要為GoogleAPI,V2則
免。
• V1 的地圖元件為 MapView,現已停用。
V2之後改為 Fragment
5
新增專案Maps
package name需與金鑰相同
根據Google 官方文件操作
https://developers.google.com/m
aps/documentation/android/start
?hl=zh-TW
6
安裝Google Play services SDK
• 請由 SDK Manager 中安裝[Google Play
services]
7
匯入到Eclipse中
• FileImport
• Existing Android Code Into Workspace
– <SDK>extras/google/google_play_services
/libproject/google-play-services_lib 專案。
8
勾選Is Library
• 請勾選Is Library,
否則無法從外部
專案匯入。
會在畫面左側看到這個lib
新增專案GMap
在專案中匯入libs
• 對專案目錄點右鍵
PropertiesAn
droid
• Add libraries,請
記得不要勾選 Is
Library。Lib本身
才要勾選。
• 完成如右圖
12
產生SHA1
• 在cmd下切換到 cd C:Program FilesJavajdk1.7.0_10bin
• 輸入:
– keytool -list -v -keystore C:Usersuser.androiddebug.keystore
• 以上紅字會因為不同電腦或軟體版本有所不同
• 金鑰密碼請直接按ENTER
13
找到SHA1 那一行,其他不是
14
自己產生debug.keystore
• C:Program FilesJava<JDK>bin>輸入:
• keytool -genkey -v -keystore <完整路徑
>debug.keystore -storepass android -alias
androiddebugkey -keypass android -dname
"CN=Android Debug,O=Android,C=US
– http://stackoverflow.com/questions/8576732/ther
e-is-no-debug-keystore-in-android-folder
• Win7 C:/Users/<帳號>/.android/
• XP  Document and Settings (路徑包含空格會造
成錯誤,可將檔案產生在其它位置)
15
Google API console
• https://code.google.com/apis/console/
#project:48090014903
16
啟動 Google Maps Android API V2服務
17
API Access取得API Key
18
格式:SHA1;package name
package name改成自己的專案名稱
19
修改AndroidManifest.xml -1
• 在<application>元素中加入子標籤
• your_api_key請填入剛剛申請好API KEY
– <meta-data
android:name="com.google.android.maps.v2.API
_KEY"
android:value="your_api_key"/>
– <meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_v
ersion"/>
20
修改AndroidManifest.xml -2
• 加入權限
– <permission
android:name="com.example.mapdemo.p
ermission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
– <uses-permission
android:name="com.example.mapdemo.p
ermission.MAPS_RECEIVE"/>
• 其中com.example.mapdemo換成自己的。
21
加入其他權限
1. <uses-permission android:name="android.permission.INTERNET"/>
2. <uses-permission
android:name="android.permission.ACCESS_NETWORK_STATE"/>
3. <uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
4. <uses-permission
android:name="com.google.android.providers.gsf.permission.READ_G
SERVICES"/>
5. <uses-permission
android:name="android.permission.ACCESS_COARSE_LOCATION"/>
6. <uses-permission
android:name="android.permission.ACCESS_FINE_LOCATION"/>
• 5, 6項只有要用到定位功能時才要加入,但通常都會用到所以就加吧
22
Layout(fragment_main.xml)
內容要改為 fragment
<?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.m
aps.MapFragment"/>
以上請將layout.xml 內容全部取代掉即可,不用改東
西
23
修改MainActivity.xml
public class MainActivity extends FragmentActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout. fragment_main);
//只載入畫面無進一步動作
}
}
載入Google Map
25
除錯小提醒
1. 請確認使用 debug.keystore 來產生 SHA1
2. 記得在 AndroidManifest.xml 中加入 API
Key 、meta data與相關權限
3. 確認網路暢通
4. 有無匯入 Google Play services libraries
26
Package 要修改的地方
如果要執行於模擬器則較麻煩
• 因為模擬器並未安裝Google Play service,所
以要另外安裝。
• 建議實機操作
• http://nkeegamedev.blogspot.tw/2012/
12/android-google-maps-api-
v2.html#uds-search-results
28
載入官方example
• https://developers.google.com/maps/d
ocumentation/android/intro#sample_co
de
• 改為自己的 package name 與 API Key
29
Google Map Javascript V3
• https://developers.google.com/maps/documenta
tion/javascript/tutorial?hl=zh-tw
• 使用 Javascript 來取得地圖網頁
• 教學:
– http://nkeegamedev.blogspot.tw/2012/12/android-
google-map-v3-1.html
• 好用的生成器:
http://www.nap.st/google_map_generator/?lang
=zh-TW
30
資料
• https://developers.google.com/maps/documentation/and
roid/start
• 原有的怎麼辦?還是可以用,但無法再取得V1 的API Key了。
• http://www.moke.tw/wordpress/computer/advanced/410
• http://nkeegamedev.blogspot.tw/2012/12/android-
google-maps-api-v2.html
• http://saleh360.blogspot.tw/2012/12/android-running-
google-maps-api-v2_12.html
• http://fecbob.pixnet.net/blog/post/38591179-google-
maps-android-api-
v2%E4%BD%BF%E7%94%A8%E5%8F%8A%E5%95%8F%E
9%A1%8C%E8%A7%A3%E6%B1%BA
31
資料
• 中研院GIS中心
• http://gis.rchss.sinica.edu.tw/
• 中研院GIS中心工具集
http://gis.ascc.net/ISTIS/tools.html
• http://simonown.wordpress.com/2009/11/
22/aa0007/
• 金門大學 http://gogkmit.wikidot.com/start
• 畫出GPS路徑
http://changyy.pixnet.net/blog/post/28058
989
32
資料
• 座標轉換
http://gis.thl.ncku.edu.tw/coordtrans/co
ordtrans.aspx
• 景點分享
• http://www.wikigps.com/
33
補充資料:取得Google MAPs
android API V2
• http://wangshifuola.blogspot.tw/2013/01/androidgo
ogle-maps-android-api-v2.html
• http://www.moke.tw/wordpress/computer/advanced/
410
• 按部就班http://cheng-min-i-
taiwan.blogspot.tw/2013/04/google-maps-android-
api-v2-android.html
34

Más contenido relacionado

Similar a Google Map Android API V2 setup guide

GDG Taichung - Flutter and Firebase.pdf
GDG Taichung - Flutter and Firebase.pdfGDG Taichung - Flutter and Firebase.pdf
GDG Taichung - Flutter and Firebase.pdfDuran Hsieh
 
GPS + Google fusion table 雲端應用
GPS + Google fusion table 雲端應用GPS + Google fusion table 雲端應用
GPS + Google fusion table 雲端應用艾鍗科技
 
Sencha touch 2 訓練課程 2 android環境建置
Sencha touch 2 訓練課程 2 android環境建置Sencha touch 2 訓練課程 2 android環境建置
Sencha touch 2 訓練課程 2 android環境建置My own sweet home!
 
[2020 .NET Conf] 企業Azure DevOps Service 實際應用架構與秘辛
[2020 .NET Conf] 企業Azure DevOps Service 實際應用架構與秘辛[2020 .NET Conf] 企業Azure DevOps Service 實際應用架構與秘辛
[2020 .NET Conf] 企業Azure DevOps Service 實際應用架構與秘辛Edward Kuo
 
App introduction
App introductionApp introduction
App introductionJerromy Lee
 
Port android to black berry 10.pptx
Port android to black berry 10.pptxPort android to black berry 10.pptx
Port android to black berry 10.pptxSimon HSU
 
CICD Workshop 20180922
CICD Workshop 20180922CICD Workshop 20180922
CICD Workshop 20180922Earou Huang
 
Visual Studio 2015 與 Git 開發實戰
Visual Studio 2015 與 Git 開發實戰Visual Studio 2015 與 Git 開發實戰
Visual Studio 2015 與 Git 開發實戰Will Huang
 
豆瓣Paa s平台 dae - 2017
豆瓣Paa s平台 dae - 2017豆瓣Paa s平台 dae - 2017
豆瓣Paa s平台 dae - 2017Tianwei Liu
 
HTML5 生态系统和应用架构模型
HTML5 生态系统和应用架构模型HTML5 生态系统和应用架构模型
HTML5 生态系统和应用架构模型Tom Fan
 
Android gradle 从入门到gg 0
Android gradle 从入门到gg 0Android gradle 从入门到gg 0
Android gradle 从入门到gg 0Jun Liu
 
導入 Flutter 前你應該知道的事
導入 Flutter 前你應該知道的事導入 Flutter 前你應該知道的事
導入 Flutter 前你應該知道的事Weizhong Yang
 
GitHub android 40項熱門技術
GitHub android 40項熱門技術GitHub android 40項熱門技術
GitHub android 40項熱門技術勝全 謝
 
Service Integration Workshop
Service Integration WorkshopService Integration Workshop
Service Integration WorkshopRyan Chung
 

Similar a Google Map Android API V2 setup guide (15)

Firebase 基礎上手 |2小時由入門到精通 | GDSC NYCU
 Firebase 基礎上手 |2小時由入門到精通 | GDSC NYCU Firebase 基礎上手 |2小時由入門到精通 | GDSC NYCU
Firebase 基礎上手 |2小時由入門到精通 | GDSC NYCU
 
GDG Taichung - Flutter and Firebase.pdf
GDG Taichung - Flutter and Firebase.pdfGDG Taichung - Flutter and Firebase.pdf
GDG Taichung - Flutter and Firebase.pdf
 
GPS + Google fusion table 雲端應用
GPS + Google fusion table 雲端應用GPS + Google fusion table 雲端應用
GPS + Google fusion table 雲端應用
 
Sencha touch 2 訓練課程 2 android環境建置
Sencha touch 2 訓練課程 2 android環境建置Sencha touch 2 訓練課程 2 android環境建置
Sencha touch 2 訓練課程 2 android環境建置
 
[2020 .NET Conf] 企業Azure DevOps Service 實際應用架構與秘辛
[2020 .NET Conf] 企業Azure DevOps Service 實際應用架構與秘辛[2020 .NET Conf] 企業Azure DevOps Service 實際應用架構與秘辛
[2020 .NET Conf] 企業Azure DevOps Service 實際應用架構與秘辛
 
App introduction
App introductionApp introduction
App introduction
 
Port android to black berry 10.pptx
Port android to black berry 10.pptxPort android to black berry 10.pptx
Port android to black berry 10.pptx
 
CICD Workshop 20180922
CICD Workshop 20180922CICD Workshop 20180922
CICD Workshop 20180922
 
Visual Studio 2015 與 Git 開發實戰
Visual Studio 2015 與 Git 開發實戰Visual Studio 2015 與 Git 開發實戰
Visual Studio 2015 與 Git 開發實戰
 
豆瓣Paa s平台 dae - 2017
豆瓣Paa s平台 dae - 2017豆瓣Paa s平台 dae - 2017
豆瓣Paa s平台 dae - 2017
 
HTML5 生态系统和应用架构模型
HTML5 生态系统和应用架构模型HTML5 生态系统和应用架构模型
HTML5 生态系统和应用架构模型
 
Android gradle 从入门到gg 0
Android gradle 从入门到gg 0Android gradle 从入门到gg 0
Android gradle 从入门到gg 0
 
導入 Flutter 前你應該知道的事
導入 Flutter 前你應該知道的事導入 Flutter 前你應該知道的事
導入 Flutter 前你應該知道的事
 
GitHub android 40項熱門技術
GitHub android 40項熱門技術GitHub android 40項熱門技術
GitHub android 40項熱門技術
 
Service Integration Workshop
Service Integration WorkshopService Integration Workshop
Service Integration Workshop
 

Más de CAVEDU Education

Google TPU Edge SBC_190424
Google TPU Edge SBC_190424Google TPU Edge SBC_190424
Google TPU Edge SBC_190424CAVEDU Education
 
From computational Thinking to computational Action - Dr. Hal Abelson, MIT Ap...
From computational Thinking to computational Action - Dr. Hal Abelson, MIT Ap...From computational Thinking to computational Action - Dr. Hal Abelson, MIT Ap...
From computational Thinking to computational Action - Dr. Hal Abelson, MIT Ap...CAVEDU Education
 
BBC Micro:bit beginner project
BBC Micro:bit beginner projectBBC Micro:bit beginner project
BBC Micro:bit beginner projectCAVEDU Education
 
LINE Messaging API with LinkIt 7697
LINE Messaging API with LinkIt 7697 LINE Messaging API with LinkIt 7697
LINE Messaging API with LinkIt 7697 CAVEDU Education
 
Latte panda workshop_japan
Latte panda workshop_japanLatte panda workshop_japan
Latte panda workshop_japanCAVEDU Education
 
拿鐵熊貓外殼設計0707
拿鐵熊貓外殼設計0707拿鐵熊貓外殼設計0707
拿鐵熊貓外殼設計0707CAVEDU Education
 
LinkIt 7697 outer case - DesignSpark Mechanical / Onkscape
LinkIt 7697 outer case - DesignSpark Mechanical / OnkscapeLinkIt 7697 outer case - DesignSpark Mechanical / Onkscape
LinkIt 7697 outer case - DesignSpark Mechanical / OnkscapeCAVEDU Education
 
170615 國中小自造者教育師資培訓營
170615  國中小自造者教育師資培訓營170615  國中小自造者教育師資培訓營
170615 國中小自造者教育師資培訓營CAVEDU Education
 
170522_Raspberry Pi 相容開發板
170522_Raspberry Pi 相容開發板170522_Raspberry Pi 相容開發板
170522_Raspberry Pi 相容開發板CAVEDU Education
 
Maker Movement and Education in Taiwan
Maker Movement and Education in TaiwanMaker Movement and Education in Taiwan
Maker Movement and Education in TaiwanCAVEDU Education
 
物聯網教學與上海深圳maker行
物聯網教學與上海深圳maker行物聯網教學與上海深圳maker行
物聯網教學與上海深圳maker行CAVEDU Education
 
IBM以雲端技術與物聯網創新產業應用@2016 New Taipei Maker Faire
IBM以雲端技術與物聯網創新產業應用@2016 New Taipei Maker FaireIBM以雲端技術與物聯網創新產業應用@2016 New Taipei Maker Faire
IBM以雲端技術與物聯網創新產業應用@2016 New Taipei Maker FaireCAVEDU Education
 
AAEON 當創客碰上UP板 - Intel Cherry Trail 高效能maker開發者平台@2016 new taipei maker faire
AAEON 當創客碰上UP板 - Intel Cherry Trail 高效能maker開發者平台@2016 new taipei maker faireAAEON 當創客碰上UP板 - Intel Cherry Trail 高效能maker開發者平台@2016 new taipei maker faire
AAEON 當創客碰上UP板 - Intel Cherry Trail 高效能maker開發者平台@2016 new taipei maker faireCAVEDU Education
 
物聯網好棒棒 您專屬的IoT私有雲平台
物聯網好棒棒 您專屬的IoT私有雲平台物聯網好棒棒 您專屬的IoT私有雲平台
物聯網好棒棒 您專屬的IoT私有雲平台CAVEDU Education
 
絕地武士心靈控制家用雲端智慧型物聯網光劍搭載無線路由器光劍底座Final
絕地武士心靈控制家用雲端智慧型物聯網光劍搭載無線路由器光劍底座Final絕地武士心靈控制家用雲端智慧型物聯網光劍搭載無線路由器光劍底座Final
絕地武士心靈控制家用雲端智慧型物聯網光劍搭載無線路由器光劍底座FinalCAVEDU Education
 
LinkIt ONE tutorial #1- Basics
LinkIt ONE tutorial #1- BasicsLinkIt ONE tutorial #1- Basics
LinkIt ONE tutorial #1- BasicsCAVEDU Education
 
LinkIt ONE tutorial #2- Communication and cloud service
LinkIt ONE tutorial #2- Communication and cloud serviceLinkIt ONE tutorial #2- Communication and cloud service
LinkIt ONE tutorial #2- Communication and cloud serviceCAVEDU Education
 

Más de CAVEDU Education (20)

Google TPU Edge SBC_190424
Google TPU Edge SBC_190424Google TPU Edge SBC_190424
Google TPU Edge SBC_190424
 
From computational Thinking to computational Action - Dr. Hal Abelson, MIT Ap...
From computational Thinking to computational Action - Dr. Hal Abelson, MIT Ap...From computational Thinking to computational Action - Dr. Hal Abelson, MIT Ap...
From computational Thinking to computational Action - Dr. Hal Abelson, MIT Ap...
 
180321 MIT見聞分享
180321   MIT見聞分享180321   MIT見聞分享
180321 MIT見聞分享
 
BBC Micro:bit beginner project
BBC Micro:bit beginner projectBBC Micro:bit beginner project
BBC Micro:bit beginner project
 
LINE Messaging API with LinkIt 7697
LINE Messaging API with LinkIt 7697 LINE Messaging API with LinkIt 7697
LINE Messaging API with LinkIt 7697
 
Latte panda workshop_japan
Latte panda workshop_japanLatte panda workshop_japan
Latte panda workshop_japan
 
拿鐵熊貓外殼設計0707
拿鐵熊貓外殼設計0707拿鐵熊貓外殼設計0707
拿鐵熊貓外殼設計0707
 
LinkIt 7697 outer case - DesignSpark Mechanical / Onkscape
LinkIt 7697 outer case - DesignSpark Mechanical / OnkscapeLinkIt 7697 outer case - DesignSpark Mechanical / Onkscape
LinkIt 7697 outer case - DesignSpark Mechanical / Onkscape
 
170615 國中小自造者教育師資培訓營
170615  國中小自造者教育師資培訓營170615  國中小自造者教育師資培訓營
170615 國中小自造者教育師資培訓營
 
170522_Raspberry Pi 相容開發板
170522_Raspberry Pi 相容開發板170522_Raspberry Pi 相容開發板
170522_Raspberry Pi 相容開發板
 
LinkIt 7697 IoT tutorial
LinkIt 7697 IoT tutorialLinkIt 7697 IoT tutorial
LinkIt 7697 IoT tutorial
 
Maker Movement and Education in Taiwan
Maker Movement and Education in TaiwanMaker Movement and Education in Taiwan
Maker Movement and Education in Taiwan
 
物聯網教學與上海深圳maker行
物聯網教學與上海深圳maker行物聯網教學與上海深圳maker行
物聯網教學與上海深圳maker行
 
161123
161123161123
161123
 
IBM以雲端技術與物聯網創新產業應用@2016 New Taipei Maker Faire
IBM以雲端技術與物聯網創新產業應用@2016 New Taipei Maker FaireIBM以雲端技術與物聯網創新產業應用@2016 New Taipei Maker Faire
IBM以雲端技術與物聯網創新產業應用@2016 New Taipei Maker Faire
 
AAEON 當創客碰上UP板 - Intel Cherry Trail 高效能maker開發者平台@2016 new taipei maker faire
AAEON 當創客碰上UP板 - Intel Cherry Trail 高效能maker開發者平台@2016 new taipei maker faireAAEON 當創客碰上UP板 - Intel Cherry Trail 高效能maker開發者平台@2016 new taipei maker faire
AAEON 當創客碰上UP板 - Intel Cherry Trail 高效能maker開發者平台@2016 new taipei maker faire
 
物聯網好棒棒 您專屬的IoT私有雲平台
物聯網好棒棒 您專屬的IoT私有雲平台物聯網好棒棒 您專屬的IoT私有雲平台
物聯網好棒棒 您專屬的IoT私有雲平台
 
絕地武士心靈控制家用雲端智慧型物聯網光劍搭載無線路由器光劍底座Final
絕地武士心靈控制家用雲端智慧型物聯網光劍搭載無線路由器光劍底座Final絕地武士心靈控制家用雲端智慧型物聯網光劍搭載無線路由器光劍底座Final
絕地武士心靈控制家用雲端智慧型物聯網光劍搭載無線路由器光劍底座Final
 
LinkIt ONE tutorial #1- Basics
LinkIt ONE tutorial #1- BasicsLinkIt ONE tutorial #1- Basics
LinkIt ONE tutorial #1- Basics
 
LinkIt ONE tutorial #2- Communication and cloud service
LinkIt ONE tutorial #2- Communication and cloud serviceLinkIt ONE tutorial #2- Communication and cloud service
LinkIt ONE tutorial #2- Communication and cloud service
 

Google Map Android API V2 setup guide