gpt4 book ai didi

c# - 如何在xamarin中获取当前的gps坐标

转载 作者:太空宇宙 更新时间:2023-11-03 21:29:32 25 4
gpt4 key购买 nike

我想在xamarin中为ios获取用户当前的经纬度。

我看过其他帖子,据我了解。

就像:

CLLocationManager lm = new CLLocationManager();
... (Acurray)
... (Other Specs)
lm.StartUpdatingLocation();
lm.Location.Coordinate.Latitude.ToString();
lm.Location.Coordinate.Longitude.ToString();

但是,当我在模拟器中运行它时,它什么也没做。它不会要求我打开我的定位服务或使用经纬度更新我的标签。

此外,我如何让它检查位置服务是否打开以及是否打开。如何让用户去做。 (比如一些应用程序上的弹出窗口要求你打开你的 GPS)

最佳答案

CLLocationManger 是异步的 - 它会在位置更新时触发事件。

CLLocationManager lm = new CLLocationManager(); //changed the class name
... (Acurray)
... (Other Specs)

lm.LocationsUpdated += delegate(object sender, CLLocationsUpdatedEventArgs e) {
foreach(CLLocation l in e.Locations) {
Console.WriteLine(l.Coordinate.Latitude.ToString() + ", " +l.Coordinate.Longitude.ToString());
}
};

lm.StartUpdatingLocation();

关于c# - 如何在xamarin中获取当前的gps坐标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25015791/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com