Xamarin表单-iOS CLLocationCoordinate2D未正确初始化 [英] Xamarin Forms - iOS CLLocationCoordinate2D is not initializing correctly

查看:59
本文介绍了Xamarin表单-iOS CLLocationCoordinate2D未正确初始化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试初始化

注意:我多次删除了该应用程序,还从项目文件夹中删除了 bin obj 文件夹,并且也对解决方案进行了清理和重建,我90%的人确信这不仅仅是调试程序的问题,因为坐标将反映到地图中,并且显示的位置是(0,0).

编辑:经过一些测试,我发现几乎同时在同一属性上两次调用了OnElementPropertyChanged,该属性是一个不可为null的布尔值,所以我不知道当值已经相同(默认值,false)时如何进入方法,所以我只是在属性仅为true时进行了检查,并且它停止执行此操作.但我还是不明白问题的最后一部分是怎么发生的.

解决方案

我发现,几乎同时在同一属性上两次调用了OnElementPropertyChanged,即使在iOS中,即使该属性以默认值,它总是首先在PropertyChanged上传递,我只是需要防止在同一事件上多次调用,并且它解决了我的问题,我希望有人可以提供比此更好的答案

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.

解决方案

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

这篇关于Xamarin表单-iOS CLLocationCoordinate2D未正确初始化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆