Xamarin Forms - iOS CLLocationCoordinate2D is not initializing correctly

时光怂恿深爱的人放手 提交于 2021-01-29 06:53:42

问题


I'm trying to initialize a CLLocationCoordinate2D class in a iOS custom render that i have, and in the constructor i can pass a Latitude and Longitude (double, double) as parameters to initialize it, but whatever the values i give, the class always comes with the default double value for the Latitude and Longitude. (0,0), here is how i tried to initialize it at first:

CLLocationCoordinate2D iosCoords = new CLLocationCoordinate2D(38.00000000000000, -9.00000000000000);
//This inits has (0,0)
//Note: the double has 14 numbers in the decimal part

also tried:

CLLocationCoordinate2D iosCoords = new CLLocationCoordinate2D();
iosCoords.Latitude = 38.00000000000000;
iosCoords.Longitude = -9.00000000000000;
//Still (0,0)

And then i thought it might have to do with the number of decimals i have, so i simplify and the weirdest thing happened:

CLLocationCoordinate2D iosCoords = new CLLocationCoordinate2D();
iosCoords.Latitude = 38;
iosCoords.Longitude = -9;
//it gives (0,-9)

Can someone point out what i'm doing wrong or how should i do this? this is pretty standart so i don't know what is causing this or what i'm even doing wrong. i'm using a real device for testing, and a real mac for hosting, here is a screenshot of the last code:

Note: i deleted the app several times, also deleted the bin and obj folders from the project folders and did the clean and rebuild on the solution too, and i'm 90% sure that it's not just a debugger problem, because the coords are going to be reflected into a map, and it's showing the location at the (0,0).

Edit: After some testing, i found out that the OnElementPropertyChanged was being called twice for the same property almost at the same time, the property is an non nullable boolean, so i don't know how it enter the method when the value was already the same (default value, false), so i just did a check when the property was only true, and it stopped doing this. but i still dont understand how the last part of my question happened.


回答1:


I found out that the OnElementPropertyChanged was being called twice for the same property almost at the same time, and it seems that in iOS even if the property starts with the default value, it always passes first on the PropertyChanged, i just needed to prevent multiple calls on the same event and it fixed my problem, i hope someone can give a better anwser than this



来源:https://stackoverflow.com/questions/57857888/xamarin-forms-ios-cllocationcoordinate2d-is-not-initializing-correctly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!