我想在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();
