0

In my android app I am using the osmdroid framework. In the framework I am using the MyLocationNewOverlay() which contains a method to show the current location on the map.

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).

Is there a standard way to use a LocationProvider that also works with the network provider if gps is not available?

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!

3
  • 1
    "new GpsMyLocationProvider" Pretty sure that's your problem Commented Sep 13, 2017 at 14:25
  • 1
    The problem is a class named GpsMyLocationProvider is either horribly named, or it only uses GPS. Look for a NetworkMyLocationProvider, or WifiMyLocationProvider. Heck, look at the source code- its only adding a single source of location data, and that's GPS. Commented Sep 13, 2017 at 14:50
  • Ah man, how embarrassing: the problem was even in the name. I just couldn't see it no more. Thanks! Commented Sep 13, 2017 at 17:02

1 Answer 1

5

The problem is that the GpsMyLocationProvider only adds the GPS_Provider to its sources (you can see that in the constructor). To add the network provider use the addLocationSource as following.

private void initMyLocationNewOverlay() { GpsMyLocationProvider provider = new GpsMyLocationProvider(context); provider.addLocationSource(LocationManager.NETWORK_PROVIDER); myLocationNewOverlay = new MyLocationNewOverlay(provider, mapView); myLocationNewOverlay.enableMyLocation(); mapView.getOverlays().add(myLocationNewOverlay); } 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.