2014-11-25 43 views
-1

我在使用LocationListener.But獲取應用程序中的當前位置時,當我將縮放應用於地圖時,第一次縮放會顯示當前位置,但放大一段時間後會放大。我無法找到過去的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) { 
} 

}

+0

地圖通常放大中心,所以如果你不在地圖的中心,那麼連續的縮放將縮小你的視野。只需實現'map.setMyLocationEnabled(true)'給你一個按鈕來平移到你當前的位置。 – j4rey89 2014-11-25 07:37:42

+0

感謝您的回覆,但在我的地圖 – Durga 2014-11-25 07:57:19

+0

上沒有setMyLocationEnabled(true)方法,您需要使用'mapView.getMap()'獲得對'GoogleMap'的引用。然後'googleMap.setMyLocationEnabled(true)'。 – j4rey89 2014-11-25 08:45:25

回答

0

你需要setCenter()與您當前的位置

試試下面的代碼

 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(); 

} 
0

在ArcGIS你能證明這樣的當前用戶位置:

LocationDisplayManager mLDM = mMapView.getLocationDisplayManager(); 

mLDM.setShowLocation(true);