nis_px nis_px - 2 years ago 231
Android Question

GoogleMap.OnCameraIdleListener Mapbox equivalent

I am looking for an GoogleMap.OnCameraIdleListener equivalent in the Mapbox Android SDK.


When panning around the map I need to query some geojson from a server, which is to be shown on the map.

For this I need to be able to detect when the map have moved and is once again idle. Google Maps have the OnCameraIdleListener and OpenLayers have the 'moveend' event. I can't use Google Maps due to some licensing issues and I'm trying to find a native alternative to OpenLayers, which I currently use.

What I have tried

I have tried to use various listeners offered by the MapboxMap class, but all of them is called much too often. Like the following:

map.setOnCameraChangeListener(new MapboxMap.OnCameraChangeListener() {
public void onCameraChange(CameraPosition position) {
Log.d("TAG", map.getProjection().getVisibleRegion().latLngBounds.toString());

The method is called a lot of times (every 400ms I think during panning). If I were to use the method directly the server load would be much too large as well as handling the returned data.

I could make a workaround that only calls the server if no CameraChange event has occurred for 5-800ms, but it would result in some not-to-nice code.

Possible duplicates

I found the following in the MapBox github:

The issue seem very similar. I have tried the proposed solutions, but without a satisfying result.

Have I missed some implementation or does someone know of a nice workaround?

Thanks in advance.

Answer Source
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download