【发布时间】:2015-12-04 15:36:26
【问题描述】:
我们能否在 OSMDroid 上启用“GotoMyLocation”按钮,例如 GoogleMap 上的mMap.setMyLocationEnabled(true);?
我在 MapView 类中没有找到这样的功能。
【问题讨论】:
-
你解决了吗?
标签: osmdroid
我们能否在 OSMDroid 上启用“GotoMyLocation”按钮,例如 GoogleMap 上的mMap.setMyLocationEnabled(true);?
我在 MapView 类中没有找到这样的功能。
【问题讨论】:
标签: osmdroid
创建其中之一
org.osmdroid.views.overlay.mylocation.MyLocationNewOverlay mylocation = new MyLocationNewOverlay(...);
将其添加到您的 MapView
mMapView.getOverlays().add(mylocation);
那就试试
mylocation.enableFollowLocation();
【讨论】:
要设置您当前使用的位置,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){}
};
【讨论】: