【发布时间】:2012-12-30 18:45:35
【问题描述】:
这是我用来查找当前位置的代码,但它没有准确地指向位置,它返回的位置为 9.920473,78.102423 而不是 9.909076, 78.100758
我不知道我哪里出错了,请帮助我提出建议。
try {
locationManager = (LocationManager) mContext.getSystemService(LOCATION_SERVICE);
// getting GPS status
isGPSEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
// getting network status
isNetworkEnabled = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
if (!isGPSEnabled && !isNetworkEnabled) {
// no network provider is enabled
}
else {
this.canGetLocation = true;
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();
}
Log.e("latitude", ""+latitude);
Log.e("longitude", ""+longitude);
}
}
// if GPS Enabled get lat/long using GPS Services
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();
}
Log.e("latitude", ""+latitude);
Log.e("longitude", ""+longitude);
}
}
}
}
}
【问题讨论】:
-
放大够了吗?假设您的 gps 返回不正确的值是遥不可及的。
-
请注意,您正在记录网络和 gps 位置 - 也许您应该在日志中指出用户正在查看的位置?另外,为什么要对两者都进行测试?如果是 gps,你不关心网络,否则如果网络 - 你的粒度不会很好。
-
放大够了吗?抱歉,我无法得到它@Siddharth,你能解释一下吗? . .
-
如果缩小,将无法准确定位并识别返回的gps是否正确。对吧?
-
回答标题:不,它没有。你解释错了
标签: android map geolocation