2014-11-25 2 views
-1

LocationListener.But을 사용하여 응용 프로그램에서 현재 위치를 가져 오는 중입니다. 문제는 처음으로 줌이 현재 위치를 보여 주지만 얼마 후에 줌이 바다로 간다는 것입니다.줌 익스텐트를 사용하여 현재 위치를 얻는 방법

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) { 
} 

: 나는 지난 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을 말해주십시오 }

당신이 당신의 현재 위치와 setCenter() 할 필요가
+0

지도 중앙을 확대하면지도의 중심에 있지 않으면 연속 줌이 축소됩니다. 현재 위치로 이동하는 버튼을 제공하기 위해'map.setMyLocationEnabled (true)'를 구현하십시오. – j4rey89

+0

답장을 보내 주셔서 감사합니다.하지만 내지도에 setMyLocationEnabled (true) 메서드가 없습니다. – Durga

+0

'mapView.getMap()'을 사용하여 'GoogleMap'에 대한 참조를 가져와야합니다. 그럼'googleMap.setMyLocationEnabled (true)'. – j4rey89

답변

0

 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); 
관련 문제