如何获得当前在xamarin中的GPS坐标

我想获取用户的当前经度和纬度ios在Xamarin。

我看了其他职位,据我了解。

就像是:

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

但是,当我在模拟器中运行它不会做任何事情。 它并不要求我打开我的位置服务或更新我的标签的经纬度。

另外,我如何使它检查位置服务打开,如果他们不是。 如何让用户做到这一点。 (如在某些应用程序上popup,要求您打开您的GPS)

CLLocationManger是asynchronous的 – 它将在更新位置时触发事件。

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