SlideShare a Scribd company logo
1 of 56
ANDROID
基礎開發課程 (2)
Presented by
Duran Hsieh
http://dog0416.blogspot.tw/
OUTLINE
• 課程目標與進度
• Google map API key
• Google map API 介紹與使用
• Google map API 事件與
FrameLayout
• Google map API UI
• Google map API 繪製線
• 目前問題彙整
• 實作:Google map 與GPS感測
器互動
• Q&A
3Presented By: Duran Hsieh
課程目標與進度
• 課程目標
• Android 基礎知識
• 名詞解釋
• 運作原理、生命週期
• Android Studio 介紹與操作
• Android App 開發實作
• Android 專案架構說明、Java 學習
• Layout、Components 介紹、操作與程式實作
• 地圖互動程式製作
• Material design
• 上架教學
• 如何將你的 App 上架
• 廣告
4Presented By: Duran Hsieh
課程目標與進度
•課程進度
日期 說明
04月06日 Android 基礎知識與安裝環境
Android上使用GPS感測器
作業:GPS 範例程式
04月13日 期中考放假
04月20日 Android Google map API
作業:建立地圖範例程式
04月27日 Material Design、地圖互動程式製作、產生APK與APP上架
作業:準備小專題
05月18日 小專題成果驗收 - DEMO
GOOGLE MAP API KEY
6Presented By: Duran Hsieh
GOOGLE MAP API KEY
• 方法1.
• 前往 https://console.developers.google.com/,並登入帳戶
7Presented By: Duran Hsieh
GOOGLE MAP API KEY
• 建立新專案
8Presented By: Duran Hsieh
GOOGLE MAP API KEY
• 建立API Key
9Presented By: Duran Hsieh
GOOGLE MAP API KEY
• 取得API Key
???
10Presented By: Duran Hsieh
GOOGLE MAP API KEY
• 新增 API 限制
11Presented By: Duran Hsieh
GOOGLE MAP API KEY
12Presented By: Duran Hsieh
GOOGLE MAP API KEY
13Presented By: Duran Hsieh
GOOGLE MAP API KEY
• 放置您的google map api key
14Presented By: Duran Hsieh
GOOGLE MAP API KEY
• 方法2.
• 建立一個新的google map activity
15Presented By: Duran Hsieh
GOOGLE MAP API KEY
• 找到google_maps_api.xml 並閱讀說明
16Presented By: Duran Hsieh
GOOGLE MAP API KEY
• 貼上網址,開始註冊API Key
17Presented By: Duran Hsieh
GOOGLE MAP API KEY
• 建立 api key
18Presented By: Duran Hsieh
GOOGLE MAP API KEY
• 建立完成
19Presented By: Duran Hsieh
GOOGLE MAP API KEY
• API key建立完成,也給有了限制
20Presented By: Duran Hsieh
GOOGLE MAP API KEY
• 填上API key
ANDROID
GOOGLE MAP API
介紹與使用
22Presented By: Duran Hsieh
ANDROID GOOGLE MAP API 介紹與使用
• 常用語法
• 經緯度(LatLng)
• 標記(MarkerOptions)
• 加入地圖
new MarkerOptions()
.position(latlng)
.title("標題")
.snippet("描述")
.draggable(true);
LatLng latlng = new LatLng(-34, 151);
mMap.addMarker(new MarkerOptions().position(latlng));
23Presented By: Duran Hsieh
ANDROID GOOGLE MAP API 介紹與使用
• 更多標記(MarkerOptions)
MarkerOptions()
.icon(BitmapDescriptorFactory.fromResource(R.drawable.common_full_open_on_phone))
.anchor(0.0f, 1.0f)
.position(new LatLng(41.889, -87.622));
24Presented By: Duran Hsieh
ANDROID GOOGLE MAP API 介紹與使用
• 移動位置
• 縮放
mMap.moveCamera(CameraUpdateFactory.newLatLng(new LatLng(-34, 151)));
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom( new LatLng(-34, 151),13));
25Presented By: Duran Hsieh
ANDROID GOOGLE MAP API 介紹與使用
• 地圖類型
• GoogleMap.MAP_TYPE_SATELLITE
• GoogleMap.MAP_TYPE_NONE
• GoogleMap.MAP_TYPE_NORMAL
• GoogleMap.MAP_TYPE_HYBRID
• GoogleMap.MAP_TYPE_TERRAIN
• 設定地圖類型
mMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
26Presented By: Duran Hsieh
ANDROID GOOGLE MAP API 介紹與使用
• 開始撰寫第一個 map activity
• 加入套件 (com.google.android.gms:play-services-maps)
• 加入google map api key
• 加入 fragment (XML)
• 加入程式
27Presented By: Duran Hsieh
ANDROID GOOGLE MAP API 介紹與使用
• 加入套件
• 方法1:file -> project structure
28Presented By: Duran Hsieh
ANDROID GOOGLE MAP API 介紹與使用
• app - > dependencies
• 找到 com.google.android.gms:play-services-maps:10.2.1
29Presented By: Duran Hsieh
ANDROID GOOGLE MAP API 介紹與使用
• 方法2:
• build.gradle - > dependencies
• 於dependencies 內加上 com.google.android.gms:play-
services-maps:10.2.1
30Presented By: Duran Hsieh
ANDROID GOOGLE MAP API 介紹與使用
• 加入 google map api key
31Presented By: Duran Hsieh
ANDROID GOOGLE MAP API 介紹與使用
• 加入 fragment (XML)
32Presented By: Duran Hsieh
ANDROID GOOGLE MAP API 介紹與使用
• 加入程式碼
• Private Googlemap mMap;
• OnCreate
33Presented By: Duran Hsieh
ANDROID GOOGLE MAP API 介紹與使用
• implement OnMapReadyCallback 與 onMapReady 方法
34Presented By: Duran Hsieh
ANDROID GOOGLE MAP API 介紹與使用
• implement OnMapReadyCallback 與 onMapReady 方法
Google map API 事件
與 FrameLayout
36Presented By: Duran Hsieh
GOOGLE MAP API 事件
• 事件:
• Click
• Imlpement OnMapReadyCallback 並加入 onMapReady 方法
• implement OnMapClickListener 並加入onMapClick 方法
• onMapReady 方法內加入 mMap.setOnMapClickListener(this)
• onMapClick 方法內加入 想做的事情
37Presented By: Duran Hsieh
GOOGLE MAP API 事件
• Long Click
• Imlpement OnMapReadyCallback 並加入 onMapReady 方法
• implement OnMapLongClickListener並加入 onMapLongClick方法
• onMapReady 方法內加入mMap.setOnMapLongClickListener(this)
• onMapLongClick方法內加入 想做的事情
38Presented By: Duran Hsieh
GOOGLE MAP API 事件
• Camera move
• Imlpement OnMapReadyCallback 並加入 onMapReady 方法
• implement OnCameraIdleListener並加入onCameraIdle 方法
• onMapReady 方法內加入mMap.setOnCameraIdleListener(this);
• onCameraIdle方法內加入 想做的事情
39Presented By: Duran Hsieh
FRAMELAYOUT
40Presented By: Duran Hsieh
實作:地圖事件程式
• 建立一個地圖事件程式
• 包含點擊、長按與地圖滑動事件
• 點擊與長按回傳顯示經緯度,並顯示
• “點擊”
• “長按”
• 地圖滑動時顯示中文“地圖移動中”
• 使用framelayout
GOOGLE MAP API UI
42Presented By: Duran Hsieh
GOOGLE MAP API UI
mUiSettings = mMap.getUiSettings();
mUiSettings.setZoomControlsEnabled(true);
mUiSettings.setCompassEnabled(true);
mUiSettings.setMyLocationButtonEnabled(true);
mMap.setMyLocationEnabled(true);
mUiSettings.setScrollGesturesEnabled(true);
mUiSettings.setZoomGesturesEnabled(true);
mUiSettings.setTiltGesturesEnabled(true);
mUiSettings.setRotateGesturesEnabled(true);
取得UI設定
縮放按鈕
指南針按鈕
我的位置與按鈕
滑動手勢
縮放手勢
傾斜手勢
旋轉(變換方向)手勢
43Presented By: Duran Hsieh
GOOGLE MAP API UI
• UI:
• 建立一個簡單的地圖,包含上述UI
• https://github.com/matsurigoto/AndroidGoogleMapUISett
ingExample.git
Google map API 繪製線
45Presented By: Duran Hsieh
GOOGLE MAP API 繪製線
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
LatLng taiwan = new LatLng(23.97, 120.98);
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(taiwan, 8));
mMutablePolyline = mMap.addPolyline(new PolylineOptions()
.add(A, B, C, D)
.width(5)
.color(Color.BLUE)
.clickable(true));
mMap.setOnPolylineClickListener(new GoogleMap.OnPolylineClickListener() {
@Override
public void onPolylineClick(Polyline polyline) {
polyline.setColor(polyline.getColor() ^ 0x00ffffff);
}
});
}
Step 1. 加入屬性(點、線寬、顏色、點擊)
Step 1. 加入點擊事件
46Presented By: Duran Hsieh
GOOGLE MAP API 繪製線
• AndroidGoogleMapPolylineExample:
• https://github.com/matsurigoto/AndroidGoogleMapPolyli
neExample.git
目前問題彙整
48Presented By: Duran Hsieh
目前問題彙整
• 如何找 BUG ?
Step 1. android moniter
Step 2.logcat
Step 3.error ?
49Presented By: Duran Hsieh
目前問題彙整
• 如何找 DEBUG ?
Step 1.
Set Break point
Step 2.Debug Step 3.Next Step
50Presented By: Duran Hsieh
目前問題彙整
• 問題一 Error:Tag <uses-permission> attribute name
has invalid character ' '.
51Presented By: Duran Hsieh
目前問題彙整
• 問題二 Attempt to invoke virtual method ‘android.view.Window$Callback
android.view.Window.getCallback()' on a null object reference
52Presented By: Duran Hsieh
目前問題彙整
• 問題三 程式流程
實作:
Google map 與 GPS感測器
54Presented By: Duran Hsieh
實作:GOOGLE MAP 與 GPS感測器
• 建立一個隨著使用者移動的地圖
• GPS感測器 (上週教學)
• Google map 上顯示自己目前位置(marker)
• 衛星地圖
• 地圖隨著使用者移動
• Marker隨著使用者移動
QUESTION & ANSWERS
THANK YOU FOR
WATCHING

More Related Content

Similar to Android基礎課程2 - google map android API

Google maps Javascript API v3
Google maps Javascript API v3Google maps Javascript API v3
Google maps Javascript API v3
Ryan Chung
 
Android快速发布&持续集成
Android快速发布&持续集成Android快速发布&持续集成
Android快速发布&持续集成
whykill
 
開放原始碼 Ch2.2 app - oss - google client api & app engine(ver 1.0)
開放原始碼 Ch2.2   app - oss -  google client api & app engine(ver 1.0)開放原始碼 Ch2.2   app - oss -  google client api & app engine(ver 1.0)
開放原始碼 Ch2.2 app - oss - google client api & app engine(ver 1.0)
My own sweet home!
 
GIS培训
GIS培训GIS培训
GIS培训
NewMap
 

Similar to Android基礎課程2 - google map android API (10)

再接再勵學 Swift 程式設計
再接再勵學 Swift 程式設計再接再勵學 Swift 程式設計
再接再勵學 Swift 程式設計
 
Google maps Javascript API v3
Google maps Javascript API v3Google maps Javascript API v3
Google maps Javascript API v3
 
GDG Taichung: What is new in Firebase
GDG Taichung: What is new in Firebase GDG Taichung: What is new in Firebase
GDG Taichung: What is new in Firebase
 
TrainingProgramAtMobileDevTW
TrainingProgramAtMobileDevTWTrainingProgramAtMobileDevTW
TrainingProgramAtMobileDevTW
 
Android 研发的昨天、今天 和 明天
Android 研发的昨天、今天 和 明天Android 研发的昨天、今天 和 明天
Android 研发的昨天、今天 和 明天
 
GDG Taichung - Flutter and Firebase.pdf
GDG Taichung - Flutter and Firebase.pdfGDG Taichung - Flutter and Firebase.pdf
GDG Taichung - Flutter and Firebase.pdf
 
Android快速发布&持续集成
Android快速发布&持续集成Android快速发布&持续集成
Android快速发布&持续集成
 
開放原始碼 Ch2.2 app - oss - google client api & app engine(ver 1.0)
開放原始碼 Ch2.2   app - oss -  google client api & app engine(ver 1.0)開放原始碼 Ch2.2   app - oss -  google client api & app engine(ver 1.0)
開放原始碼 Ch2.2 app - oss - google client api & app engine(ver 1.0)
 
GIS培训
GIS培训GIS培训
GIS培训
 
Google Maps 開始收費了該怎麼辦?
Google Maps 開始收費了該怎麼辦?Google Maps 開始收費了該怎麼辦?
Google Maps 開始收費了該怎麼辦?
 

More from Duran Hsieh

Study4TW .NET Conf Local Event Taichung 2018 slideshow
Study4TW .NET Conf Local Event Taichung 2018 slideshowStudy4TW .NET Conf Local Event Taichung 2018 slideshow
Study4TW .NET Conf Local Event Taichung 2018 slideshow
Duran Hsieh
 

More from Duran Hsieh (20)

聽微軟專家說為何.NET開發非學不可?
聽微軟專家說為何.NET開發非學不可?聽微軟專家說為何.NET開發非學不可?
聽微軟專家說為何.NET開發非學不可?
 
DevSecOps 實踐與 GitHub 進階安全: 建立安全的開發流程
DevSecOps 實踐與 GitHub 進階安全: 建立安全的開發流程DevSecOps 實踐與 GitHub 進階安全: 建立安全的開發流程
DevSecOps 實踐與 GitHub 進階安全: 建立安全的開發流程
 
Visual Studio Dev Tunnel.pdf
Visual Studio Dev Tunnel.pdfVisual Studio Dev Tunnel.pdf
Visual Studio Dev Tunnel.pdf
 
Cloud Study Jam - ML API 4
Cloud Study Jam -  ML API 4Cloud Study Jam -  ML API 4
Cloud Study Jam - ML API 4
 
Cloud Study Jam ML API 3
Cloud Study Jam ML API 3Cloud Study Jam ML API 3
Cloud Study Jam ML API 3
 
GDG Taichung - Firebase Introduction 01
GDG Taichung - Firebase Introduction 01GDG Taichung - Firebase Introduction 01
GDG Taichung - Firebase Introduction 01
 
Study4TW .NET Conf Local Event Taichung 2018 slideshow
Study4TW .NET Conf Local Event Taichung 2018 slideshowStudy4TW .NET Conf Local Event Taichung 2018 slideshow
Study4TW .NET Conf Local Event Taichung 2018 slideshow
 
What is .NET Chinese ver
What is .NET Chinese verWhat is .NET Chinese ver
What is .NET Chinese ver
 
Microsoft recommendation solution on azure
Microsoft recommendation solution on azureMicrosoft recommendation solution on azure
Microsoft recommendation solution on azure
 
Microsoft professional program introduction
Microsoft professional program introductionMicrosoft professional program introduction
Microsoft professional program introduction
 
聰明的投資者
聰明的投資者聰明的投資者
聰明的投資者
 
[Study4TW Visual Studio Everywhere] asp.net core 實務開發經驗分享
[Study4TW Visual Studio Everywhere] asp.net core 實務開發經驗分享[Study4TW Visual Studio Everywhere] asp.net core 實務開發經驗分享
[Study4TW Visual Studio Everywhere] asp.net core 實務開發經驗分享
 
2016年逢甲大學資訊系:ASP.NET MVC 4 教育訓練6
2016年逢甲大學資訊系:ASP.NET MVC 4 教育訓練62016年逢甲大學資訊系:ASP.NET MVC 4 教育訓練6
2016年逢甲大學資訊系:ASP.NET MVC 4 教育訓練6
 
2016年逢甲大學資訊系:ASP.NET MVC 4 教育訓練5
2016年逢甲大學資訊系:ASP.NET MVC 4 教育訓練52016年逢甲大學資訊系:ASP.NET MVC 4 教育訓練5
2016年逢甲大學資訊系:ASP.NET MVC 4 教育訓練5
 
2016年逢甲大學資訊系:ASP.NET MVC 4 教育訓練4
2016年逢甲大學資訊系:ASP.NET MVC 4 教育訓練42016年逢甲大學資訊系:ASP.NET MVC 4 教育訓練4
2016年逢甲大學資訊系:ASP.NET MVC 4 教育訓練4
 
2016年逢甲大學資訊系:ASP.NET MVC 4 教育訓練3
2016年逢甲大學資訊系:ASP.NET MVC 4 教育訓練32016年逢甲大學資訊系:ASP.NET MVC 4 教育訓練3
2016年逢甲大學資訊系:ASP.NET MVC 4 教育訓練3
 
2016年逢甲大學資訊系:ASP.NET MVC 4 教育訓練2
2016年逢甲大學資訊系:ASP.NET MVC 4 教育訓練22016年逢甲大學資訊系:ASP.NET MVC 4 教育訓練2
2016年逢甲大學資訊系:ASP.NET MVC 4 教育訓練2
 
2016年逢甲大學資訊系:ASP.NET MVC 4 教育訓練1(20160222)
2016年逢甲大學資訊系:ASP.NET MVC 4 教育訓練1(20160222)2016年逢甲大學資訊系:ASP.NET MVC 4 教育訓練1(20160222)
2016年逢甲大學資訊系:ASP.NET MVC 4 教育訓練1(20160222)
 
2015 年逢甲大學資訊系:ASP.NET MVC 4 教育訓練5
2015 年逢甲大學資訊系:ASP.NET MVC 4 教育訓練52015 年逢甲大學資訊系:ASP.NET MVC 4 教育訓練5
2015 年逢甲大學資訊系:ASP.NET MVC 4 教育訓練5
 
2015 年逢甲大學資訊系:ASP.NET MVC 4 教育訓練4
2015 年逢甲大學資訊系:ASP.NET MVC 4 教育訓練42015 年逢甲大學資訊系:ASP.NET MVC 4 教育訓練4
2015 年逢甲大學資訊系:ASP.NET MVC 4 教育訓練4
 

Android基礎課程2 - google map android API

  • 1. ANDROID 基礎開發課程 (2) Presented by Duran Hsieh http://dog0416.blogspot.tw/
  • 2. OUTLINE • 課程目標與進度 • Google map API key • Google map API 介紹與使用 • Google map API 事件與 FrameLayout • Google map API UI • Google map API 繪製線 • 目前問題彙整 • 實作:Google map 與GPS感測 器互動 • Q&A
  • 3. 3Presented By: Duran Hsieh 課程目標與進度 • 課程目標 • Android 基礎知識 • 名詞解釋 • 運作原理、生命週期 • Android Studio 介紹與操作 • Android App 開發實作 • Android 專案架構說明、Java 學習 • Layout、Components 介紹、操作與程式實作 • 地圖互動程式製作 • Material design • 上架教學 • 如何將你的 App 上架 • 廣告
  • 4. 4Presented By: Duran Hsieh 課程目標與進度 •課程進度 日期 說明 04月06日 Android 基礎知識與安裝環境 Android上使用GPS感測器 作業:GPS 範例程式 04月13日 期中考放假 04月20日 Android Google map API 作業:建立地圖範例程式 04月27日 Material Design、地圖互動程式製作、產生APK與APP上架 作業:準備小專題 05月18日 小專題成果驗收 - DEMO
  • 6. 6Presented By: Duran Hsieh GOOGLE MAP API KEY • 方法1. • 前往 https://console.developers.google.com/,並登入帳戶
  • 7. 7Presented By: Duran Hsieh GOOGLE MAP API KEY • 建立新專案
  • 8. 8Presented By: Duran Hsieh GOOGLE MAP API KEY • 建立API Key
  • 9. 9Presented By: Duran Hsieh GOOGLE MAP API KEY • 取得API Key ???
  • 10. 10Presented By: Duran Hsieh GOOGLE MAP API KEY • 新增 API 限制
  • 11. 11Presented By: Duran Hsieh GOOGLE MAP API KEY
  • 12. 12Presented By: Duran Hsieh GOOGLE MAP API KEY
  • 13. 13Presented By: Duran Hsieh GOOGLE MAP API KEY • 放置您的google map api key
  • 14. 14Presented By: Duran Hsieh GOOGLE MAP API KEY • 方法2. • 建立一個新的google map activity
  • 15. 15Presented By: Duran Hsieh GOOGLE MAP API KEY • 找到google_maps_api.xml 並閱讀說明
  • 16. 16Presented By: Duran Hsieh GOOGLE MAP API KEY • 貼上網址,開始註冊API Key
  • 17. 17Presented By: Duran Hsieh GOOGLE MAP API KEY • 建立 api key
  • 18. 18Presented By: Duran Hsieh GOOGLE MAP API KEY • 建立完成
  • 19. 19Presented By: Duran Hsieh GOOGLE MAP API KEY • API key建立完成,也給有了限制
  • 20. 20Presented By: Duran Hsieh GOOGLE MAP API KEY • 填上API key
  • 22. 22Presented By: Duran Hsieh ANDROID GOOGLE MAP API 介紹與使用 • 常用語法 • 經緯度(LatLng) • 標記(MarkerOptions) • 加入地圖 new MarkerOptions() .position(latlng) .title("標題") .snippet("描述") .draggable(true); LatLng latlng = new LatLng(-34, 151); mMap.addMarker(new MarkerOptions().position(latlng));
  • 23. 23Presented By: Duran Hsieh ANDROID GOOGLE MAP API 介紹與使用 • 更多標記(MarkerOptions) MarkerOptions() .icon(BitmapDescriptorFactory.fromResource(R.drawable.common_full_open_on_phone)) .anchor(0.0f, 1.0f) .position(new LatLng(41.889, -87.622));
  • 24. 24Presented By: Duran Hsieh ANDROID GOOGLE MAP API 介紹與使用 • 移動位置 • 縮放 mMap.moveCamera(CameraUpdateFactory.newLatLng(new LatLng(-34, 151))); mMap.moveCamera(CameraUpdateFactory.newLatLngZoom( new LatLng(-34, 151),13));
  • 25. 25Presented By: Duran Hsieh ANDROID GOOGLE MAP API 介紹與使用 • 地圖類型 • GoogleMap.MAP_TYPE_SATELLITE • GoogleMap.MAP_TYPE_NONE • GoogleMap.MAP_TYPE_NORMAL • GoogleMap.MAP_TYPE_HYBRID • GoogleMap.MAP_TYPE_TERRAIN • 設定地圖類型 mMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
  • 26. 26Presented By: Duran Hsieh ANDROID GOOGLE MAP API 介紹與使用 • 開始撰寫第一個 map activity • 加入套件 (com.google.android.gms:play-services-maps) • 加入google map api key • 加入 fragment (XML) • 加入程式
  • 27. 27Presented By: Duran Hsieh ANDROID GOOGLE MAP API 介紹與使用 • 加入套件 • 方法1:file -> project structure
  • 28. 28Presented By: Duran Hsieh ANDROID GOOGLE MAP API 介紹與使用 • app - > dependencies • 找到 com.google.android.gms:play-services-maps:10.2.1
  • 29. 29Presented By: Duran Hsieh ANDROID GOOGLE MAP API 介紹與使用 • 方法2: • build.gradle - > dependencies • 於dependencies 內加上 com.google.android.gms:play- services-maps:10.2.1
  • 30. 30Presented By: Duran Hsieh ANDROID GOOGLE MAP API 介紹與使用 • 加入 google map api key
  • 31. 31Presented By: Duran Hsieh ANDROID GOOGLE MAP API 介紹與使用 • 加入 fragment (XML)
  • 32. 32Presented By: Duran Hsieh ANDROID GOOGLE MAP API 介紹與使用 • 加入程式碼 • Private Googlemap mMap; • OnCreate
  • 33. 33Presented By: Duran Hsieh ANDROID GOOGLE MAP API 介紹與使用 • implement OnMapReadyCallback 與 onMapReady 方法
  • 34. 34Presented By: Duran Hsieh ANDROID GOOGLE MAP API 介紹與使用 • implement OnMapReadyCallback 與 onMapReady 方法
  • 35. Google map API 事件 與 FrameLayout
  • 36. 36Presented By: Duran Hsieh GOOGLE MAP API 事件 • 事件: • Click • Imlpement OnMapReadyCallback 並加入 onMapReady 方法 • implement OnMapClickListener 並加入onMapClick 方法 • onMapReady 方法內加入 mMap.setOnMapClickListener(this) • onMapClick 方法內加入 想做的事情
  • 37. 37Presented By: Duran Hsieh GOOGLE MAP API 事件 • Long Click • Imlpement OnMapReadyCallback 並加入 onMapReady 方法 • implement OnMapLongClickListener並加入 onMapLongClick方法 • onMapReady 方法內加入mMap.setOnMapLongClickListener(this) • onMapLongClick方法內加入 想做的事情
  • 38. 38Presented By: Duran Hsieh GOOGLE MAP API 事件 • Camera move • Imlpement OnMapReadyCallback 並加入 onMapReady 方法 • implement OnCameraIdleListener並加入onCameraIdle 方法 • onMapReady 方法內加入mMap.setOnCameraIdleListener(this); • onCameraIdle方法內加入 想做的事情
  • 39. 39Presented By: Duran Hsieh FRAMELAYOUT
  • 40. 40Presented By: Duran Hsieh 實作:地圖事件程式 • 建立一個地圖事件程式 • 包含點擊、長按與地圖滑動事件 • 點擊與長按回傳顯示經緯度,並顯示 • “點擊” • “長按” • 地圖滑動時顯示中文“地圖移動中” • 使用framelayout
  • 42. 42Presented By: Duran Hsieh GOOGLE MAP API UI mUiSettings = mMap.getUiSettings(); mUiSettings.setZoomControlsEnabled(true); mUiSettings.setCompassEnabled(true); mUiSettings.setMyLocationButtonEnabled(true); mMap.setMyLocationEnabled(true); mUiSettings.setScrollGesturesEnabled(true); mUiSettings.setZoomGesturesEnabled(true); mUiSettings.setTiltGesturesEnabled(true); mUiSettings.setRotateGesturesEnabled(true); 取得UI設定 縮放按鈕 指南針按鈕 我的位置與按鈕 滑動手勢 縮放手勢 傾斜手勢 旋轉(變換方向)手勢
  • 43. 43Presented By: Duran Hsieh GOOGLE MAP API UI • UI: • 建立一個簡單的地圖,包含上述UI • https://github.com/matsurigoto/AndroidGoogleMapUISett ingExample.git
  • 44. Google map API 繪製線
  • 45. 45Presented By: Duran Hsieh GOOGLE MAP API 繪製線 public void onMapReady(GoogleMap googleMap) { mMap = googleMap; LatLng taiwan = new LatLng(23.97, 120.98); mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(taiwan, 8)); mMutablePolyline = mMap.addPolyline(new PolylineOptions() .add(A, B, C, D) .width(5) .color(Color.BLUE) .clickable(true)); mMap.setOnPolylineClickListener(new GoogleMap.OnPolylineClickListener() { @Override public void onPolylineClick(Polyline polyline) { polyline.setColor(polyline.getColor() ^ 0x00ffffff); } }); } Step 1. 加入屬性(點、線寬、顏色、點擊) Step 1. 加入點擊事件
  • 46. 46Presented By: Duran Hsieh GOOGLE MAP API 繪製線 • AndroidGoogleMapPolylineExample: • https://github.com/matsurigoto/AndroidGoogleMapPolyli neExample.git
  • 48. 48Presented By: Duran Hsieh 目前問題彙整 • 如何找 BUG ? Step 1. android moniter Step 2.logcat Step 3.error ?
  • 49. 49Presented By: Duran Hsieh 目前問題彙整 • 如何找 DEBUG ? Step 1. Set Break point Step 2.Debug Step 3.Next Step
  • 50. 50Presented By: Duran Hsieh 目前問題彙整 • 問題一 Error:Tag <uses-permission> attribute name has invalid character ' '.
  • 51. 51Presented By: Duran Hsieh 目前問題彙整 • 問題二 Attempt to invoke virtual method ‘android.view.Window$Callback android.view.Window.getCallback()' on a null object reference
  • 52. 52Presented By: Duran Hsieh 目前問題彙整 • 問題三 程式流程
  • 53. 實作: Google map 與 GPS感測器
  • 54. 54Presented By: Duran Hsieh 實作:GOOGLE MAP 與 GPS感測器 • 建立一個隨著使用者移動的地圖 • GPS感測器 (上週教學) • Google map 上顯示自己目前位置(marker) • 衛星地圖 • 地圖隨著使用者移動 • Marker隨著使用者移動

Editor's Notes

  1. 1. Net core rc4 版本,dotnet new 指令有重大變更。
  2. 1. Net core rc4 版本,dotnet new 指令有重大變更。
  3. 參考資料:https://zh.wikipedia.org/wiki/Android
  4. 參考資料:https://zh.wikipedia.org/wiki/Android
  5. 參考資料:https://zh.wikipedia.org/wiki/Android
  6. 參考資料:https://zh.wikipedia.org/wiki/Android
  7. 參考資料:https://zh.wikipedia.org/wiki/Android
  8. 參考資料:https://zh.wikipedia.org/wiki/Android
  9. 參考資料:https://zh.wikipedia.org/wiki/Android
  10. 參考資料:https://zh.wikipedia.org/wiki/Android
  11. 參考資料:https://zh.wikipedia.org/wiki/Android
  12. 參考資料:https://zh.wikipedia.org/wiki/Android
  13. 參考資料:https://zh.wikipedia.org/wiki/Android
  14. 參考資料:https://zh.wikipedia.org/wiki/Android
  15. 參考資料:https://zh.wikipedia.org/wiki/Android
  16. 參考資料:https://zh.wikipedia.org/wiki/Android
  17. 參考資料:https://zh.wikipedia.org/wiki/Android
  18. <fragment xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:tools="http://schemas.android.com/tools"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:id="@+id/map"     tools:context=".MapsActivity"     android:name="com.google.android.gms.maps.SupportMapFragment" />
  19. SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager() .findFragmentById(R.id.map); mapFragment.getMapAsync(this);
  20. public void onMapReady(GoogleMap googleMap) { mMap = googleMap; // Add a marker in Sydney and move the camera LatLng sydney = new LatLng(-34, 151); mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney")); mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney)); }
  21. Google map 官方有提供範例可以參考 https://github.com/googlemaps/android-samples
  22. Note: Insert your picture by clicking on the Picture Place Holder Icon, then send it back!
  23. http://stackoverflow.com/questions/36666091/attempt-to-invoke-virtual-method-android-view-windowcallback-android-view-wind
  24. Note: Insert your picture by clicking on the Picture Place Holder Icon, then send it back!