[Google Play Service ] 取得手機的地理位置資訊
主題: |
[Google Play Service ] 取得手機的地理位置資訊 |
文章簡介: |
透過 google play service library 取得手機當下的地理位置資訊 |
作者: |
Roman Yu |
版本/產出日期: |
V1.0/2016.11.24 |
1. 前言
• 本文件用來提供Android開發人員在開發應用程式時透過google play service取得地理位置資訊之參考
2. 目的
• 透過google play service取得地理位置資訊, 並進行相關應用
3. 開始前準備
本架構建立於以下版本的環境:
• Android SDK 2.3+
• JDK 7+
• Android Studio 2.2+ (emulator or android device acquired, latest sdk recommend)
4. Setup google play service sdk
4.1、 透過Android Studio建立專案後, 設定google play service sdk
• 開啟模組設定(Open Module Settings)
• 新增google play service
(因build.gradle檔案異動, 請重新整理(執行gradle sync))
• 增訂所需要的權限
4.2、 加入GoogleApiClient
• 在onCreate當中加入欲使用的api(本例為LocationService)
• 加上Listener
• 在onPause當中加上GoogleApiClient的暫停處理
• 在onStart進行連線
4.3、 取得地理位置資訊
4.4、 顯示於畫面上
5. 參考資料
• Overview of Google Play Services
• 專案範例