Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Swift 5 String Manipulation

I am learning iOS development and I try to get Gps information from phone and send to api using Alamofire as below

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)
        }

And getting Gps information from phone as

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

when I print location.description am getting responses <+37.78583400,-122.40641700> +/- 5.00m (speed -1.00 mps / course -1.00) @ 9/15/22, 10:05:21 AM East Africa Time

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

My question is how can I manipulate this string to get substrings of latitude, longitude, time, date, speed, course and altitude. I apologise for my English am using google translator

>Solution :

you can use CLLocation class to get these values like:

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

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading