如何让xamarin当前的GPS坐标 [英] how to get the current gps coordinates in xamarin

查看:415
本文介绍了如何让xamarin当前的GPS坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获得在xamarin的ios用户当前的经度和纬度。

I would like to get the user's current latitude and longitude for ios in xamarin.

我看着其他职务,并按照我的理解。

I've looked at other posts and as i understand it.

这是这样的:

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



然而,当我在模拟器中运行它,它不会做任何事情。它不问我打开我的位置服务或更新我的经度和纬度的标签。

However, when i run it in the simulator it doesn't do anything. It doesn't ask me to turn on my location services or update my Label with the latitude and longitude.

另外,我如何让它检查一下位置服务已打开对,如果他们不是。如何让用户做到这一点。 (如弹出上的部分应用要求你打开你的GPS)

Also, how do i make it check it location services are turned on and if they're not. How to make the user do it. (like the pop up on some apps asking you to turn on your gps)

推荐答案

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

CLLocationManger is async - it will fire events when the location is updated.

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();

这篇关于如何让xamarin当前的GPS坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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