0

LocationManager を使用して位置情報を取得します。次に、場所を GeoPoint に変換し、マップに表示します。グーグルマップの表示位置となぜこんなに違うの?これは、場所を取得する方法です。

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

                    }
        });
4

2 に答える 2

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"); 
 }
}
于 2012-11-19T09:23:06.530 に答える
0

投影を使用して、ジオポイントとマップ上のポイントを変換できます。

Projection projection = mapView.getProjection(); 

GeoPoint point = new GeoPoint(lat, lng);

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

次に、OverlayItem で myPoint を使用します。

于 2012-11-19T09:51:06.440 に答える