【问题标题】:how to get the current gps coordinates in xamarin如何在xamarin中获取当前gps坐标
【发布时间】:2014-07-29 12:52:31
【问题描述】:

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

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

就像:

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

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

另外,我如何检查定位服务是否已打开以及是否未打开。如何让用户去做。 (例如某些应用程序上的弹出窗口要求您打开 GPS)

【问题讨论】:

    标签: c# ios xamarin cllocationmanager


    【解决方案1】:

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

    【讨论】:

    • 请问如何从经纬度中获取位置名称?
    • @Jason 这仍然有效吗? CLLocationManager 的命名空间是什么?那些(....) 是什么?试图获取坐标,但只是从 Xamarin 开始,所以有点迷失。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多