SWIFT 5字符串操作

wlzqhblo  于 2022-09-19  发布在  Swift
关注(0)|答案(1)|浏览(222)

我正在学习iOS开发,我尝试从手机获取GPS信息并使用Alamofire发送到API,如下所示

let parameter = ["appVersion": "1.3.1",
                         "countryCode": "TZ",
                         "deviceName": "chrome",
                         "deviceId": "Web",
                         "deviceOS": "Mac OS",
                         "deviceToken": "token",
                         "latitude":"nothing",
                         "longitude":"nothing",
                         "date":"nothing",
                         "time":"nothing"
                          "speed":"Nothing"
                         ]
        AF.request("https://mtvmax.com/api/login",method: .post,parameters: parameter).response{
            response in
            debugPrint(response)
        }

并通过手机获取GPS信息

func locationManager(_ _manager:CLLocationManager, didUpdateLocations Location:[CLLocation]){
        if let location = Location.first{
            //print(location.coordinate)
            Uilabel.text = location.description
            //print(location.description)

        }

    }

当我打印location.description时,收到响应<+37.78583400,-122.40641700> +/- 5.00m (speed -1.00 mps / course -1.00) @ 9/15/22, 10:05:21 AM East Africa Time

我的问题是如何操作这个字符串来获得纬度、经度、时间、日期、速度、航向和海拔的子字符串。我为我的英语正在使用谷歌翻译道歉

rt4zxlrg

rt4zxlrg1#

可以使用CLLocation类获取这些值,如下所示:

func locationManager(_ _manager:CLLocationManager, didUpdateLocations Location:[CLLocation]){
        if let location = Location.first{
            let altitude = location.altitude.description
            let latitude = location.coordinate.latitude.description
            let longitude = location.coordinate.longitude.description
            let timeAndDate = location.timestamp
            let speed = location.speed.description

        }

    }

相关问题