0

I am trying to get the current location and display it on a OSMdroid map inside an Android application. But I get no location and a Runnable that is supposed to be called the first time the location is found is never called.

I have tried different providers, permissions are all enabled and GPS location, too.

private void getCurrentLocation() {
    GpsMyLocationProvider provider = new GpsMyLocationProvider(this);
    provider.addLocationSource(LocationManager.GPS_PROVIDER);
    provider.addLocationSource(LocationManager.NETWORK_PROVIDER);

    myLocationOverlay = new MyLocationNewOverlay(provider, mMapView);
    myLocationOverlay.enableMyLocation();
    myLocationOverlay.setDrawAccuracyEnabled(true);

    myLocationOverlay.runOnFirstFix(new Runnable() {
        public void run() {
            // never reaches this point
            Timber.i("runOnFirstFix");
        }
    });

    mMapView.getOverlays().add(myLocationOverlay);

    if (myLocationOverlay.getMyLocation() == null) {
        // this shows up
        Timber.i("Location not retrieved");
    }
}

I understand that the location might not be found as soon as the overlay is added, but I don't understand why the Runnable doesn't work

bMain
  • 324
  • 3
  • 11
  • runtime permissions? and did you ever get a fix? – spy Mar 28 '19 at 22:35
  • Yes, the user is asked to grant permissions at runtime. Still investigating. Might be some bug in newer version of osmdroid or Android – bMain Mar 29 '19 at 12:58
  • `GPS_PROVIDER` won't work indoors and `NETWORK_PROVIDER` might need a SIM card. But you could install some "fake GPS" app from the Play Store just to test that your app should work if a location were received. – Markus Kauppinen Apr 04 '19 at 13:38

0 Answers0