2012-02-21 119 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(); 
      }