How to add a setMyLocationEnabled button on OSMap?

时光怂恿深爱的人放手 提交于 2019-12-05 20:01:16

Create one of these

org.osmdroid.views.overlay.mylocation.MyLocationNewOverlay mylocation = new MyLocationNewOverlay(...);

Add it to your MapView

mMapView.getOverlays().add(mylocation);

Then try mylocation.enableFollowLocation();

To set your current location use, LOCATION_SERVICE of LocationManager. This will listen your gps location and will set your center to the present location.

LocationManager myLocationManager = (LocationManager) getApplicationContext().getSystemService(LOCATION_SERVICE);
        LocationListenerProxy llp=new LocationListenerProxy(myLocationManager);
        llp.startListening(gpsLocationListener, 1, 1) ; 

place this code in your onCreate Activity and then define locationlistener in a different class

public final LocationListener gpsLocationListener = new LocationListener() {
      @Override
      public void onLocationChanged(Location location){  
          textView.setText(location.getLatitude()+","+location.getLongitude());
          Log.d("Location Changed >>> ", location.getLatitude()+","+location.getLongitude());
      }
      public void onProviderDisabled(String provider){}
      public void onProviderEnabled(String provider){}
      public void onStatusChanged(String provider, int status, Bundle extras){}
     };
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!