bMain
bMain

Reputation: 354

Runnable for myLocationOverlay.runOnFirstFix not called and getMyLocation() is null

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

Upvotes: 0

Views: 346

Answers (0)

Related Questions