nativescript-mapbox icon indicating copy to clipboard operation
nativescript-mapbox copied to clipboard

tap on map cause an app crash on android

Open wendt88 opened this issue 5 years ago • 6 comments

tns info

√ Getting NativeScript components versions information...
√ Component nativescript has 6.7.6 version and is up to date.
√ Component @nativescript/core has 6.5.8 version and is up to date.
√ Component tns-android has 6.5.1 version and is up to date.
√ Component tns-ios has 6.5.1 version and is up to date.

nativescript-mapbox: 5.0.1

if you tap lightly on the over side of the marker (default marker) ezgif com-video-to-gif

error

An uncaught Exception occurred on "main" thread.
Attempt to invoke virtual method 'boolean java.lang.Boolean.booleanValue()' on a null object reference

StackTrace:
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.Boolean.booleanValue()' on a null object reference
	at com.tns.gen.com.mapbox.mapboxsdk.maps.MapboxMap_OnMapClickListener.onMapClick(MapboxMap_OnMapClickListener.java:19)
	at com.mapbox.mapboxsdk.maps.MapGestureDetector.notifyOnMapClickListeners(MapGestureDetector.java:983)
	at com.mapbox.mapboxsdk.maps.MapGestureDetector$StandardGestureListener.onSingleTapConfirmed(MapGestureDetector.java:358)
	at com.mapbox.android.gestures.StandardGestureDetector$1.onSingleTapConfirmed(StandardGestureDetector.java:81)
	at android.view.GestureDetector$GestureHandler.handleMessage(GestureDetector.java:323)
	at android.os.Handler.dispatchMessage(Handler.java:107)
	at android.os.Looper.loop(Looper.java:214)
	at android.app.ActivityThread.main(ActivityThread.java:7356)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)

wendt88 avatar Jun 25 '20 13:06 wendt88

Any updates on this issue?

TPham92 avatar Jul 06 '20 19:07 TPham92

I haven't had a chance to look at it. At my present rate of progress I'll be making another major pass through the plugin in early August.

Yermo avatar Jul 06 '20 19:07 Yermo

@wendt88 I figured out the issue. If you uses setOnMapClickListener or setOnMapLongClickListener function you need to return a boolean. The new Mapbox Native SDK allows for multiple listeners on an event and follows the standard pattern of returning 'true' when a handler has handled the event and others shouldn't. Not returning a boolean from the listener function will cause a crash. https://docs.mapbox.com/android/api/map-sdk/9.2.0/index.html

EX: mapbox.setOnMapClickListener((point: LatLng) => { console.log("Map clicked at latitude: " + point.lat + ", longitude: " + point.lng); // do stuff ... return true });

TPham92 avatar Jul 08 '20 04:07 TPham92

@TPham92 good find.

Yermo avatar Jul 08 '20 05:07 Yermo

@TPham92 thx for your feedback! now i found out, that the app crashs on every map (not marker) tap. I do not have any listener. debugging a bit I found that on tap it gets called checkForCircleClickEvent as default witch returns false and the app crashs.

@Yermo could you fix this (return true) ASAP please?

wendt88 avatar Jul 09 '20 14:07 wendt88

@wendt88 I figured out the issue. If you uses setOnMapClickListener or setOnMapLongClickListener function you need to return a boolean. The new Mapbox Native SDK allows for multiple listeners on an event and follows the standard pattern of returning 'true' when a handler has handled the event and others shouldn't. Not returning a boolean from the listener function will cause a crash. https://docs.mapbox.com/android/api/map-sdk/9.2.0/index.html

EX: mapbox.setOnMapClickListener((point: LatLng) => { console.log("Map clicked at latitude: " + point.lat + ", longitude: " + point.lng); // do stuff ... return true });

Thank you, It's work very fine in my Nativescript-Vue application.
In Vue you need to make a little change in the code, remove the function arrow:

mapbox.setOnMapClickListener(function(point: LatLng) {
    console.log("Map clicked at latitude: " + point.lat + ", longitude: " + point.lng); 
    // do stuff ... 
    return true 
});

ignacio68 avatar Oct 23 '20 07:10 ignacio68