0

here I pass latitude and longitude of source and destination place and I got response but how to get specific value from response.I am new in ios Developer.I pass lat and long in google API like this

  let travelTimeString : NSString = "https://maps.googleapis.com/maps/api/directions/json?origin=19.120912,72.845121&destination=19.110162,72.853951&sensor=false" as NSString

    print("travelTimeString",travelTimeString)
    let urlStr  = travelTimeString.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
    let searchURL: NSURL = NSURL(string: urlStr! as String)!
    do {
        let newdata = try Data(contentsOf: searchURL as URL)
        if let responseDictionary = try JSONSerialization.jsonObject(with: newdata, options: []) as? NSDictionary {
            print("travelTimeString",responseDictionary)


        }} catch {
    }

i got response like this so how to get value of duration(routes-->legs-->duration)

Faster
  • 41
  • 2
  • 11

1 Answers1

0

You could use any external library, or parse by hand like:

 if let routes = responseDictionary["routes"] as? NSDictionary {
     if let legs = routes["legs"] as? NSDictionary {
        // etc
     }
 }
Taier
  • 2,109
  • 12
  • 22