Skip to content Skip to sidebar Skip to footer

Googlemap.setonmaploadedcallback Is Not Called

I want to get location with using googleMap and geocode features. Place find my right latitude,longitude, formatted address. onMapReady function is called but onMapLoaded function

Solution 1:

Try this code, You haven't called right lifecycle methods of the MapView. It's already explained in the docs

You custom View:

publicclassCustomMapViewextendsLinearLayout {

privateMapView mapView;
privateTextView textView;

publicCustomMapView(Context context) {
    this(context, null);
}

publicCustomMapView(Context context, AttributeSet attrs) {
    super(context, attrs);
    initialize(context);
}

publicvoidonCreate(Bundle var1) {
    mapView.onCreate(var1);
}

publicvoidonResume() {
    mapView.onResume();
}

publicvoidonPause() {
    mapView.onPause();
}

publicvoidonStart() {
    mapView.onStart();
}

publicvoidonStop() {
    mapView.onStop();
}

publicvoidonDestroy() {
    mapView.onDestroy();
}

publicvoidonLowMemory() {
    mapView.onLowMemory();
}

publicvoidonSaveInstanceState(Bundle var1) {
    mapView.onSaveInstanceState(var1);
}

privatevoidinitialize(Context context) {
    setOrientation(LinearLayout.VERTICAL);
    LayoutInflater.from(context).inflate(R.layout.map_view, this, true);

    this.mapView = ViewUtil.findById(this, R.id.map_view);
    this.textView = ViewUtil.findById(this, R.id.address_view);
}

publicvoiddisplay(Place place) {
    this.mapView.setVisibility(View.VISIBLE);
    this.imageView.setVisibility(View.GONE);

    this.mapView.getMapAsync(newOnMapReadyCallback() {
        @OverridepublicvoidonMapReady(final @Nonnull GoogleMap googleMap) {

            googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(place.getLatLong(), 13));
            googleMap.addMarker(newMarkerOptions().position(place.getLatLong()));
            googleMap.setBuildingsEnabled(true);
            googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
            googleMap.getUiSettings().setAllGesturesEnabled(false);
            googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(place.getLatLong(), googleMap.getMaxZoomLevel() - 4));

            googleMap.setOnMapLoadedCallback(newGoogleMap.OnMapLoadedCallback() {
                @OverridepublicvoidonMapLoaded() {

                    googleMap.snapshot(newGoogleMap.SnapshotReadyCallback() {
                        @OverridepublicvoidonSnapshotReady(Bitmap bitmap) {

                            // it is not called
                        }
                    });
                }
            });
        }
    });

    this.textView.setText(place.getDescription());
}

Your Activity

publicclassMainActivityextendsActivity {
    privateCustomMapView customView;

    @OverridepublicvoidonCreate(Bundle var1) {
        super.onCreate(var1);

        customView = ViewUtil.findById(this, R.id.custom_view_id);
        customView.onCreate(var1);
    }

    @OverridepublicvoidonResume() {
        super.onResume();
        customView.onResume();
    }

    @OverridepublicvoidonPause() {
        super.onPause();
        customView.onPause();
    }

    @OverridepublicvoidonStart() {
        super.onStart();
        customView.onStart();
    }

    @OverridepublicvoidonStop() {
        super.onStop();
        customView.onStop();
    }

    @OverridepublicvoidonDestroy() {
        super.onDestroy();
        customView.onDestroy();
    }

    @OverridepublicvoidonLowMemory() {
        super.onLowMemory();
        customView.onLowMemory();
    }

    @OverridepublicvoidonSaveInstanceState(Bundle var1) {
        super.onSaveInstanceState(var1);
        customView.onSaveInstanceState(var1);
    }
}

Post a Comment for "Googlemap.setonmaploadedcallback Is Not Called"