【问题标题】:How to take only Latitude and Longitude values from CLLocation instead of taking full location details in swift如何仅从 CLLocation 中获取纬度和经度值,而不是快速获取完整的位置详细信息
【发布时间】:2018-03-22 10:34:23
【问题描述】:

我正在尝试从 cllocation 中获取纬度和经度值。它即将到来的完整位置数据。因为我只需要纬度和经度数据来发送我的后端。我必须向服务器发送多个经纬度数据。

即使我尝试使用 CLLocationCoordinate2D,但是,它在发送到服务器时在数据中获取 CLLocationCoordinate。

我想同时接受纬度和经度的单个数组,而不是两个 数组。

谁能建议我,如何只取纬度和经度值 快速追加到数组?

这是我的代码

    var myLocations: [CLLocation] = []

    func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
        myLocations.append(locations[0] as CLLocation)


}
output is
<+10.92088132,+77.56955708> +/- 1414.00m (speed -1.00 mps / course -1.00) @ 22/03/18, 1:17:30 PM India Standard Time

[<+10.92088132,+77.56955708> +/- 1414.00m (speed -1.00 mps / course -1.00) @ 22/03/18, 1:17:30 PM India Standard Time]

【问题讨论】:

    标签: ios swift latitude-longitude cllocation location-services


    【解决方案1】:

    你可以试试

    let loc = myLocations.last
    
    let lat = currentLocation.coordinate.latitude
    
    let lon = currentLocation.coordinate.longitude
    

    然后像这样声明 arr

        var myLocations: [String] = []
    
        let last = locations[0] as CLLocation
    
        myLocations.append("\(last.coordinate.latitude),\(last.coordinate.longitude)")
    

    【讨论】:

    • 我想同时接受纬度和经度的单个数组,而不是两个数组。
    • 如果我取 CLLocationCoordinate2D,在数组 CLLocationCoordinate2D 中也会显示,但是,我只想要纬度和经度值。
    • 每一个对象都使用 obj.latitude 和 objc.longitude 来获取值
    • @Sh_Khan 然后不要打印整个东西,只打印实际坐标print("\(coordinate.latitude), \(coordinate.longitude)")
    • 它在你编辑后工作。接受您的回答并投了赞成票。
    【解决方案2】:
        var  location = CLLocation()
        location = myLocations.last! as CLLocation   
        let lat = location.coordinate.latitude
        let longit = location.coordinate.longitude
    

    【讨论】:

    • 这里,你如何添加到 mylocations 变量?
    • 您只能附加纬度和经度,并可以根据您的要求发送到服务器
    • 我不想单独添加两个
    • @AnilkumariOSdeveloper .. 是的,您只能在一个数组中追加
    • 我需要像 [{latitude : value, longitude : value}, {latitude : value, longitude : value}] 这样的格式
    猜你喜欢
    • 1970-01-01
    • 2016-08-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-08
    • 1970-01-01
    相关资源
    最近更新 更多