2015-09-04 35 views
0

我正在开发一个基于地图视图的应用程序,获取经度和纬度,并在地图上显示用于绘制路线的图表。当我在路上尝试应用程序时(使用自行车),那么得到错误的经纬度就意味着像循环一样获得方向和路线。如何在Android应用上获取精确的经度和纬度坐标?

我想要精确的Android应用程序的纬度和经度坐标。

我用于定位的波纹码。

public Location getLocation() { 
    try { 
     locationManager = (LocationManager) this.getApplicationContext().getSystemService(LOCATION_SERVICE); 
     // getting GPS status 
     isGPSEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER); 
     // getting network status 
     isNetworkEnabled = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER); 
     if (!isGPSEnabled && !isNetworkEnabled) { 
      Toast.makeText(this, "Youe GPS service is not enabled",Toast.LENGTH_SHORT).show(); 
     } else { 
       if (isNetworkEnabled) { 
       locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,GPS_TIME_INTERVAL,GPS_DISTANCE, this); 
       Log.d("Network", "Network"); 
       if (locationManager != null) { 
        location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); 
        if (location != null) { 
         latitude = location.getLatitude(); 
         longitude = location.getLongitude(); 
        } 
       } 
       } 
      else if (isGPSEnabled) { 
        if (location == null) { 
         locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,GPS_TIME_INTERVAL,GPS_DISTANCE, this); 
         Log.d("GPS Enabled", "GPS Enabled"); 
         if (locationManager != null) { 
          location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); 
          if (location != null) { 
           latitude = location.getLatitude(); 
           longitude = location.getLongitude(); 
          } 
         } 
        } 
       } 
      if(location != null) 
      persistLocation(location); 
      stopUsingGPS(); 
     } 
    } catch (Exception e) { 
     e.printStackTrace(); 
    } 
    return location; 
} 
+0

你可以调用:'requestLocationUpdates',但是你没有显示那个回调的代码。这就是准确读数的来源。 – weston

+0

此外,为什么你更喜欢GPS上的网络位置?并阅读:http://developer.android.com/guide/topics/location/strategies.html你不需要身体离开房子来测试你的应用程序。 – weston

+0

@Lucky,你使用谷歌地图吗? –

回答