Map breaks on android when moving to current location (Android only)
See original GitHub issueHi Torben,
In my app I am centring the view above the current user location when the map page appears. I do this by implementing the UserLocationChangedCommand and call MoveToRegion.
On iOS everything is working fine, unfortunately my Android version breaks when re-opening the map page. The break occurs when:
- Don’t change first default region, change page, return to map, then change the map -> BREAK (first in video)
- Change the map region, change page, return to map -> BREAK (second in video)
Below please find the Stack Trance, some of my code and a link to a video showing the problem. The application breaks somewhere in the background, stack trace is taken from the output window.
Stack Trace
Unhanded Exception:
System.NullReferenceException: Object reference not set to an instance of an object.
07-14 12:20:55.145 D/Mono ( 2345): DllImport attempting to load: ‘/system/lib/liblog.so’. 07-14 12:20:55.145 D/Mono ( 2345): DllImport loaded library ‘/system/lib/liblog.so’. 07-14 12:20:55.145 D/Mono ( 2345): DllImport searching in: ‘/system/lib/liblog.so’ (‘/system/lib/liblog.so’). 07-14 12:20:55.145 D/Mono ( 2345): Searching for ‘__android_log_print’. 07-14 12:20:55.145 D/Mono ( 2345): Probing ‘__android_log_print’. 07-14 12:20:55.145 D/Mono ( 2345): Found as ‘_android_log_print’. 07-14 12:20:55.149 I/MonoDroid( 2345): UNHANDLED EXCEPTION: 07-14 12:20:55.149 I/MonoDroid( 2345): System.NullReferenceException: Object reference not set to an instance of an object. 07-14 12:20:55.149 I/MonoDroid( 2345): at TK.CustomMap.Droid.TKCustomMapRenderer.MoveToCenter () [0x0000f] in <filename unknown>:0 07-14 12:20:55.149 I/MonoDroid( 2345): at TK.CustomMap.Droid.TKCustomMapRenderer.FormsMapPropertyChanged (System.Object sender, System.ComponentModel.PropertyChangedEventArgs e) [0x0005d] in <filename unknown>:0 07-14 12:20:55.149 I/MonoDroid( 2345): at (wrapper delegate-invoke) <Module>:invoke_void_object_PropertyChangedEventArgs (object,System.ComponentModel.PropertyChangedEventArgs) 07-14 12:20:55.149 I/MonoDroid( 2345): at Xamarin.Forms.BindableObject.OnPropertyChanged (System.String propertyName) [0x0000a] in C:\BuildAgent3\work\aad494dc9bc9783\Xamarin.Forms.Core\BindableObject.cs:137 07-14 12:20:55.149 I/MonoDroid( 2345): at Xamarin.Forms.Element.OnPropertyChanged (System.String propertyName) [0x00000] in C:\BuildAgent3\work\aad494dc9bc9783\Xamarin.Forms.Core\Element.cs:362 07-14 12:20:55.149 I/MonoDroid( 2345): at TK.CustomMap.TKCustomMap.OnPropertyChanged (System.String propertyName) [0x00000] in <filename unknown>:0 07-14 12:20:55.149 I/MonoDroid( 2345): at Xamarin.Forms.BindableObject.SetValueActual (Xamarin.Forms.BindableProperty property, Xamarin.Forms.BindablePropertyContext context, System.Object value, Boolean currentlyApplying, SetValueFlags attributes, Boolean silent) [0x000f4] in C:\BuildAgent3\work\aad494dc9bc9783\Xamarin.Forms.Core\BindableObject.cs:581 07-14 12:20:55.149 I/MonoDroid( 2345): at Xamarin.Forms.BindableObject.SetValueCore (Xamarin.Forms.BindableProperty property, System.Object value, SetValueFlags attributes, SetValuePrivateFlags privateAttributes) [0x0014b] in C:\BuildAgent3\work\aad494dc9bc9783\Xamarin.Forms.Core\BindableObject.cs:378 07-14 12:20:55.149 I/MonoDroid( 2345): at Xamarin.Forms.BindableObject.SetValue (Xamarin.Forms.BindableProperty property, System.Object value, Boolean fromStyle, Boolean checkAccess) [0x0005f] in C:\BuildAgent3\work\aad494dc9bc9783\Xamarin.Forms.Core\BindableObject.cs:531 07-14 12:20:55.149 I/MonoDroid( 2345): at Xamarin.Forms.BindableObject.SetValue (Xamarin.Forms.BindableProperty property, System.Object value) [0x00000] in C:\BuildAgent3\work\aad494dc9bc9783\Xamarin.Forms.Core\BindableObject.cs:83 07-14 12:20:55.149 I/MonoDroid( 2345): at TK.CustomMap.TKCustomMap.set_MapCenter (Position value) [0x00000] in <filename unknown>:0 07-14 12:20:55.149 I/MonoDroid( 2345): at TK.CustomMap.Droid.TKCustomMapRenderer.OnCameraChange (System.Object sender, Android.Gms.Maps.CameraChangeEventArgs e) [0x0001f] in <filename unknown>:0 07-14 12:20:55.149 I/MonoDroid( 2345): at Android.Gms.Maps.GoogleMap+IOnCameraChangeListenerImplementor.OnCameraChange (Android.Gms.Maps.Model.CameraPosition position) [0x0001a] in <filename unknown>:0 07-14 12:20:55.149 I/MonoDroid( 2345): at Android.Gms.Maps.GoogleMap+IOnCameraChangeListenerInvoker.n_OnCameraChange_Lcom_google_android_gms_maps_model_CameraPosition (IntPtr jnienv, IntPtr native__this, IntPtr native_position) [0x00011] in <filename unknown>:0 07-14 12:20:55.149 I/MonoDroid( 2345): at (wrapper dynamic-method) System.Object:02c591bd-9913-41ba-9f4a-89ccdc181512 (intptr,intptr,intptr) 07-14 12:20:55.153 D/Mono ( 2345): DllImport searching in: ‘__Internal’ (’(null)'). 07-14 12:20:55.153 D/Mono ( 2345): Searching for ‘java_interop_jnienv_throw’. 07-14 12:20:55.153 D/Mono ( 2345): Probing ‘java_interop_jnienv_throw’. 07-14 12:20:55.153 D/Mono ( 2345): Found as ‘java_interop_jnienv_throw’. An unhandled exception occurred
In mgmain JNI_OnLoad 07-14 12:20:55.709 E/mono ( 2345): 07-14 12:20:55.709 E/mono ( 2345): Unhanded Exception:. 07-14 12:20:55.709 E/mono ( 2345): System.NullReferenceException: Object reference not set to an instance of an object. 07-14 12:20:55.709 E/mono ( 2345): at (wrapper dynamic-method) System.Object:02c591bd-9913-41ba-9f4a-89ccdc181512 (intptr,intptr,intptr) 07-14 12:20:55.709 E/mono ( 2345): at (wrapper native-to-managed) System.Object:02c591bd-9913-41ba-9f4a-89ccdc181512 (intptr,intptr,intptr) 07-14 12:20:55.709 E/mono-rt ( 2345): [ERROR] FATAL UNHANDLED EXCEPTION: System.NullReferenceException: Object reference not set to an instance of an object. 07-14 12:20:55.709 E/mono-rt ( 2345): at (wrapper dynamic-method) System.Object:02c591bd-9913-41ba-9f4a-89ccdc181512 (intptr,intptr,intptr) 07-14 12:20:55.709 E/mono-rt ( 2345): at (wrapper native-to-managed) System.Object:02c591bd-9913-41ba-9f4a-89ccdc181512 (intptr,intptr,intptr)
Code
TKCustomMap map = new TKCustomMap()
{
IsShowingUser = true,
MapType = MapType.Street,
IsRegionChangeAnimated = true,
VerticalOptions = LayoutOptions.FillAndExpand,
HorizontalOptions = LayoutOptions.FillAndExpand
};
map.MoveToRegion(MapSpan.FromCenterAndRadius(new Position(ConfigAccess.DefaultLatitude, ConfigAccess.DefaultLongitude), Distance.FromMeters(ConfigAccess.DefaultDistance)));
map.SetBinding(TKCustomMap.CustomPinsProperty, "Pins");
map.SetBinding(TKCustomMap.SelectedPinProperty, "SelectedPin");
map.SetBinding(TKCustomMap.MapRegionProperty, "MapRegion");
map.SetBinding(TKCustomMap.MapCenterProperty, "MapCenter");
map.SetBinding(TKCustomMap.CalloutClickedCommandProperty, "CalloutClickedCommand");
map.UserLocationChangedCommand = new Command<Position>(p =>
{
if (!_viewIsAppearing) return;
map.MoveToRegion(MapSpan.FromCenterAndRadius(p, Distance.FromMeters(ConfigAccess.DefaultDistance)));
_viewIsAppearing = false;
});
Link to video
Please let me know if you need any more information from me.
Thanks and kind regards, Nikolai
Issue Analytics
- State:
- Created 7 years ago
- Comments:12 (4 by maintainers)
Top GitHub Comments
Unfortunately not, I’m sorry. I just dont have enough time. I have a lot of projects currently and became a father recently. I’ll try to find some time…
Guys check out this issue they may be related: https://github.com/TorbenK/TK.CustomMap/issues/214
It looks like formsmap is null in some onproperty changed events. this might be the same case in your function as well.
P.S if you guys wanna test some more drop the pdb files into your references and put a breakpoints in that function to find out what is null. Attached are the files if you wanna just drop them into your nuget lib folder for tkcustom maps. Just keep in mind i used version 1.5.2 pre1.
Debug.zip