如何使用缩放范围获取当前位置

时间:2014-11-25 07:25:01

标签: android arcgis

我使用LocationListener获取我的应用程序中的当前位置。但问题是当我应用缩放到地图时,第一次缩放显示当前位置但是在一段时间后缩放到海。我无法找到解决方案从过去3天开始,请告诉我任何一个

我的活动

   loc = mMapView.getLocationDisplayManager();
    loc.setAutoPanMode(AutoPanMode.LOCATION);
    loc.setLocationListener(new MyLocationListener(LaunchingMapActivity.this,mMapView)); 
     loc.start();
            mLocation = loc.getPoint();
            Log.e("mLocation", ""+mLocation);
            mapLocatiomFromLoc = loc.getLocation();

            double longitude=mapLocatiomFromLoc.getLongitude();
            double latitude=mapLocatiomFromLoc.getLatitude();
            p=new Point((float)longitude,(float)latitude);

MyLocationListener:

 public class MyLocationListener implements LocationListener {
Geometry mLocation = null;
private MapView mMapView;
private Context mContext;


public MyLocationListener(Context context,MapView mapView) {
    super();
    this.mMapView=mapView;
}

/**
 * If location changes, update our current location. If being found for
 * the first time, zoom to our current position with a resolution of 20
 */
public void onLocationChanged(Location loc1) {
    if (loc1 == null)
        return;
    boolean zoomToMe = (mLocation == null) ? true : false;
    mLocation = new Point(loc1.getLongitude(), loc1.getLatitude());
    Log.e("ONCHANGEmLocation", ""+mLocation);
    if (zoomToMe) {

         Point mPoint = (Point) GeometryEngine.project(mLocation, SpatialReference.create(20439)
                    ,SpatialReference.create(20439));
        Log.e("mPoint",""+ mPoint);
        // graphic = new Graphic((Geometry) p, (Symbol) sms, hm);
        // locationLayer.addGraphic(graphic);
       // mMapView.zoomToResolution(mPoint, 20.0);
    }
}

public void onProviderDisabled(String provider) {
    Toast.makeText(mContext, "GPS Disabled",
            Toast.LENGTH_SHORT).show();
}

public void onProviderEnabled(String provider) {
    Toast.makeText(mContext, "GPS Enabled",
            Toast.LENGTH_SHORT).show();
}

public void onStatusChanged(String provider, int status, Bundle extras) {
}

}

2 个答案:

答案 0 :(得分:0)

您需要使用当前位置设置Center()

尝试以下代码

     MapController mc;
    public void onLocationChanged(Location location) {

   List<Overlay> overlays = mapView.getOverlays();
   myLocOverlay = new MyLocationOverlay(this, mapView);
   overlays.add(myLocOverlay);
   myLocOverlay.enableMyLocation();*

   // definitely need what's below
   int lat = (int) (location.getLatitude() * 1E6);
   int lng = (int) (location.getLongitude() * 1E6);
   GeoPoint point = new GeoPoint(lat, lng);
   mc.setCenter(point);
   mapView.invalidate();

}

答案 1 :(得分:0)

在ArcGIS中,您可以显示当前用户位置:

LocationDisplayManager mLDM = mMapView.getLocationDisplayManager();

mLDM.setShowLocation(true);