2012-02-21 137 views
1

是否有可能在沒有去戶外的情況下獲得緯度&?我目前的情況是,用戶必須在室外才能找到他們的位置,而在這個位置上,他們需要相當長的時間才能獲得他們的位置。我希望我的用戶能夠在室內找到他們的位置。Android:獲取緯度和經度

+0

爲什麼用戶需要在室外獲取他們的位置?是否由於網絡問題? – noob 2012-02-21 05:39:49

+0

@Creator GPS只能在戶外使用,而且需要清晰的路徑才能從定位儀獲取數據。當你在室內時,有屋頂和牆壁,所以路徑被阻擋,你無法從斜角石獲得數據。 – J1and1 2012-08-08 09:01:47

回答

0

是的,它是可能的話,從下面的代碼提示:

try { 
      gps_enabled = locManager.isProviderEnabled(LocationManager.GPS_PROVIDER); 
     } catch (Exception ex) { 
     } 
     try { 
      network_enabled = locManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER); 
     } catch (Exception ex) { 
     } 

     if (!gps_enabled && !network_enabled) { 
      // show alert 
     } 
     if (network_enabled) { 
      locManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locListener); 
     } 
     if (gps_enabled) { 
      locManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locListener); 
     } 
+0

謝謝,很好解釋。 – DroidMatt 2012-02-21 10:20:21

0

是的,這是可能的,你在門內獲得你的網絡。所以你可以使用LocationManager.NETWORK_PROVIDER獲得GPS協調員。

請看看這個answer

0

這取決於你所使用的GPS提供商和信號availabiliy固定的位置,我想你只使用GPS供應商,所以它不是在門工作,請嘗試使用網絡供應商也考慮。

此外,使用最後已知的位置,按時間GPS定位的位置,有一個很好的博客最早獲取位置。

android-developers.blogspot.in/2011/06/deep-dive-into-location.html

0
LocationManager locManager; 
    Location location; 
double lat; 
double lng; 
    try { 
       gps_enabled = locManager.isProviderEnabled(LocationManager.GPS_PROVIDER); 
      } catch (Exception ex) { 
      } 
      try { 
       network_enabled = locManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER); 
      } catch (Exception ex) { 
      } 

      if (!gps_enabled && !network_enabled) { 
       // show alert 
      } 
      if (network_enabled) { 
        locManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);     
       locManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,1000,1, locationListener); 
       location = locManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); 
      lat = location.getLatitude(); 
      lng = location.getLongitude(); 
      } 
      if (gps_enabled) { 
       locManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);    
       locManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,1000,1, locationListener); 
       location = locManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); 
      lat = location.getLatitude(); 
      lng = location.getLongitude(); 
      }