2012-11-19 81 views
0

我使用LocationManager獲取位置。然後將位置轉換爲GeoPoint並將其顯示在地圖上。爲什麼它與Google地圖顯示位置有很大不同? 這是獲取位置的方法:地圖中的GeoPoint與Google地圖顯示位置不同

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 

        } 
     }); 

回答

1

試試這個。

LocationListener locationListener = new LocationListener() { 
    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"); 
} 
} 
0

您可以使用投影在GeoPoints和地圖上的點之間進行轉換。

Projection projection = mapView.getProjection(); 

GeoPoint point = new GeoPoint(lat, lng); 

Point myPoint = new Point(); 
projection.toPixels(point, myPoint); 

那麼你會在你的OverlayItem使用myPoint

相關問題