为什么用LocationManager获得的location转换成GeoPoint显示在地图上,和谷歌地图显示的位置相差很大?
为什么用LocationManager获得的location转换成GeoPoint显示在地图上,和谷歌地图显示的位置相差很大?这是获得location的代码
mLocationManager = (LocationManager)this.getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
criteria.setAltitudeRequired(false);
criteria.setBearingRequired(false);
criteria.setCostAllowed(true);
criteria.setPowerRequirement(Criteria.POWER_LOW);
final String strLocationProvider = mLocationManager.getBestProvider(criteria, true);
mLocationManager.requestLocationUpdates(strLocationProvider, 1000, 0,
new LocationListener(){
@Override
public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
double geoLatitude = mLocation.getLatitude()*1E6;
double geoLongitude = mLocation.getLongitude()*1E6;
GeoPoint currentGeoPoint = new GeoPoint((int)geoLatitude,(int)geoLongitude);
mapCon.animateTo(currentGeoPoint); }
@Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onStatusChanged(String provider, int status,
Bundle extras) {
// TODO Auto-generated method stub
}
});
--------------------编程问答-------------------- 试试这个方法:
LocationListener locationListener = new LocationListener() {--------------------编程问答-------------------- 你可以使用Projection在GeoPoints和Map中的Points之间转化。
public void onLocationChanged(Location location) {
int lat = (int) (location.getLatitude() * 1E6);
int lng = (int) (location.getLongitude() * 1E6);
GeoPoint point = new GeoPoint(lat, lng);
OverlayItem overlayitem4 = new OverlayItem(point, "You Are Here", "Boulder, CO");
}
}
Projection projection = mapView.getProjection();
GeoPoint point = new GeoPoint(lat, lng);
Point myPoint = new Point();
projection.toPixels(point, myPoint);
然后在OverlayItem中使用 myPoint方法。 --------------------编程问答-------------------- 我觉得应该是系统服务提供的位置信息有问题。上述两种方法不异于我的代码。 --------------------编程问答-------------------- 通过测试,确实是locationManager给出的经纬度与googleMap获得的经纬度不一样。这是为什么呢?
补充:移动开发 , Android