0
在我的设备上,一切运行良好,但其他人显示可怕的距离。像它应该是从点300米,它显示6000公里寻找我的位置和计算距离
这里就是我如何得到我的位置:
private SharedPreferences sPref;
private LocationManager locationManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.start_layout);
sPref=getSharedPreferences(ShareTag, MODE_PRIVATE);
locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
}
@Override
protected void onResume() {
super.onResume();
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,
1000 * 10, 10, locationListener);
locationManager.requestLocationUpdates(
LocationManager.NETWORK_PROVIDER, 1000 * 10, 10,
locationListener);
}
private LocationListener locationListener = new LocationListener() {
@Override
public void onLocationChanged(Location location) {
Log.d("MyLog", "my lat="+location.getLatitude()+" splash mylong="+location.getLongitude());
saveCoordinates(location);
}
@Override
public void onProviderDisabled(String provider) {
}
@Override
public void onProviderEnabled(String provider) {
//do nothing
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
if (provider.equals(LocationManager.GPS_PROVIDER)) {
//do nothing
} else if (provider.equals(LocationManager.NETWORK_PROVIDER)) {
//do nothing
}
}
};
private void saveCoordinates(Location location){
Log.d("MyLog","get in the save coord");
Editor ed=sPref.edit();
ed.putString("myLatitude", ""+location.getLatitude());
ed.putString("myLongtitude", ""+location.getLongitude());
ed.commit();
}
}
这就是我如何得到我的坐标,并将其储存
然后,当我需要获得距离
sPref=context.getSharedPreferences(ShareTag, context.MODE_PRIVATE);
myLatitude=Double.parseDouble(sPref.getString("myLatitude", "0"));
myLongtitude=Double.parseDouble(sPref.getString("myLongtitude", "0"));
float[] result = new float[1];
latitude=address.getLatitude();
longtitude=address.getLongitude();
Location.distanceBetween(latitude, longtitude, myLatitude, myLongtitude, result);
因此,结果[0]显示不切实际的数字。 longtitude=address.getLongitude();
和latitude=address.getLatitude();
是正确的,所以问题是myLatitude和myLongtitude。我无法查看这些设备的日志以查看用户的坐标是否错误。我的GPS工作不正常(chineese设备),所以我从网络服务提供商获取我的坐标 - 可能这就是他们正确的原因。
我该怎么办?有什么建议?