【问题标题】:how to get time value from google api in swift 3.0如何在swift 3.0中从google api获取时间价值
【发布时间】:2018-06-27 09:37:05
【问题描述】:

在这里我传递了源和目标位置的纬度和经度,我得到了响应,但是如何从响应中获取特定值。我是 ios Developer 的新手。我像这样在 google API 中传递 lat 和 long

  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 那么如何获得持续时间的价值(路线-->腿-->持续时间)

【问题讨论】:

    标签: swift google-maps swift3 google-api google-distancematrix-api


    【解决方案1】:

    您可以使用任何外部库,或手动解析,例如:

     if let routes = responseDictionary["routes"] as? NSDictionary {
         if let legs = routes["legs"] as? NSDictionary {
            // etc
         }
     }
    

    【讨论】:

      猜你喜欢
      • 2011-08-24
      • 1970-01-01
      • 2016-01-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-21
      • 1970-01-01
      相关资源
      最近更新 更多