[英]Get current location with network provider on osmdroid
In my android app I am using the osmdroid framework. 在我的Android应用程序中,我正在使用osmdroid框架。 In the framework I am using the MyLocationNewOverlay() which contains a method to show the current location on the map.
在框架中,我使用MyLocationNewOverlay(),其中包含一种在地图上显示当前位置的方法。
My problem 我的问题
The LocationListener in the framework seems not to use the network provider and only wants to locate me with GPS (which works fine, but only if I am outside). 框架中的LocationListener似乎不使用网络提供商,而只想使用GPS定位我(这很好,但仅当我在外面时)。
Is there a standard way to use a LocationProvider that also works with the network provider if gps is not available? 如果gps不可用,有没有一种使用LocationProvider的标准方法,该方法也可以与网络提供商一起使用?
AndroidManifest.xml AndroidManifest.xml
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
Pretty standard to init my location overlay: 初始化我的位置叠加层的相当标准:
private void initMyLocationNewOverlay() {
myLocationNewOverlay = new MyLocationNewOverlay(new GpsMyLocationProvider(context), mapView);
myLocationNewOverlay.enableMyLocation();
mapView.getOverlays().add(myLocationNewOverlay);
}
Thanks in advance! 提前致谢!
The problem is that the GpsMyLocationProvider only adds the GPS_Provider to its sources (you can see that in the constructor). 问题是GpsMyLocationProvider仅将GPS_Provider添加到其源中(您可以在构造函数中看到它)。 To add the network provider use the
addLocationSource
as following. 要添加网络提供商,请使用
addLocationSource
,如下所示。
private void initMyLocationNewOverlay() {
GpsMyLocationProvider provider = new GpsMyLocationProvider(context);
provider.addLocationSource(LocationManager.NETWORK_PROVIDER);
myLocationNewOverlay = new MyLocationNewOverlay(provider, mapView);
myLocationNewOverlay.enableMyLocation();
mapView.getOverlays().add(myLocationNewOverlay);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.