2016-03-27 59 views
1

我無法從GPS獲取精確的緯度,經度。我需要獲取Android地圖上谷歌地圖上的小藍色指針(我的當前位置)的位置......但我是獲取手動放置紅色標記的位置。 這裏是ScreenSnap .. enter image description here 這裏是獲取紅色標記位置的代碼。無法從GPS獲取準確的位置

   if (isNetworkEnabled) { 
       locationManager.requestLocationUpdates(
         LocationManager.NETWORK_PROVIDER, 
         MIN_TIME_BW_UPDATES, 
         MIN_DISTANCE_CHANGE_FOR_UPDATES, this); 
       if (locationManager != null) { 
        location = locationManager 
          .getLastKnownLocation(LocationManager.NETWORK_PROVIDER); 
        if (location != null) { 
         latitude = location.getLatitude(); 
         longitude = location.getLongitude(); 
        } 
       } 
       if(isGPSEnabled) { 
       if(location == null) { 
        locationManager.requestLocationUpdates(
          LocationManager.GPS_PROVIDER, 
          MIN_TIME_BW_UPDATES, 
          MIN_DISTANCE_CHANGE_FOR_UPDATES, this); 

        if(locationManager != null) { 
         location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); 

         if(location != null) { 
          latitude = location.getLatitude(); 
          longitude = location.getLongitude(); 
         } 
        } 
       } 
      } 
+0

你是不是從GPS設備請求您所在的位置爲你的主題建議。使用GPS設備來確定你的位置。 – greenapps

+0

sory我粘貼只有一塊代碼...我編輯帖子與第二個功能,它需要從GPS的位置... –

+0

我只需要知道...有任何方式(功能)來獲取位置的建在地圖上標註的「藍點」?因爲它總是被標記在完美的位置點。 –

回答

0

使用'FusedLocationApi.requestLocationUpdates'獲取當前位置。融合的位置提供商是Google Play服務中的位置API之一。它管理底層的定位技術並提供一個簡單的API,以便您可以在高層指定需求。另外,不要忘記啓用設備GPS。

下面是FusedLocationApi樣本演示應用程序,它展示瞭如何使用API​​說:https://github.com/codepath/android-google-maps-demo/blob/master/app/src/main/java/com/example/mapdemo/MapDemoActivity.java

+1

是的,我試過,但在第一個它給了我最後的位置.. doest給我當前的位置......這就是爲什麼我再次切換到這段代碼。 –