如何在OSMap上添加setMyLocationEnabled按钮?

时间:2015-12-04 15:36:27

标签: osmdroid

我们可以在OSMDroid上启用“GotoMyLocation”按钮,例如GoogleMap上的mMap.setMyLocationEnabled(true);吗?

我在MapView类中找不到这样的功能。

2 个答案:

答案 0 :(得分:1)

创建其中一个

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

将其添加到MapView

mMapView.getOverlays().add(mylocation);

然后试试 mylocation.enableFollowLocation();

答案 1 :(得分:0)

要设置当前位置,请使用LocationManager的LOCATION_SERVICE。这将听取您的GPS位置,并将您的中心设置为当前位置。

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

将此代码放在onCreate Activity中,然后在另一个类

中定义locationlistener
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){}
     };