【问题标题】:GoogleMaps iOS - Getting straight line instead of a routeGoogleMaps iOS - 获得直线而不是路线
【发布时间】:2016-04-06 19:53:19
【问题描述】:

我正在为我的 iOS 应用程序使用 GoogleMaps 路线来显示我当前位置和所选地点之间的路线。为此,我使用折线,问题在于它绘制的是直线而不是路线。

有人可以帮忙吗?

【问题讨论】:

    标签: ios google-maps routes google-polyline google-directions-api


    【解决方案1】:

    我解决了我的问题。这是我的代码和解释,如果有人遇到同样的问题。

    在您获得从 Google API 路线获取路线的网址之后。您执行以下操作(我使用了来自 github 的 SwiftyJSON):

                let url = NSURL(string: urlString)
                let request = NSURLRequest(URL: url!)
                let session = NSURLSession(configuration: NSURLSessionConfiguration.defaultSessionConfiguration())
                let task = session.dataTaskWithRequest(request) { (data, response, error) -> Void in
    
                    if error == nil
                    {
                        let swiftyJSON = JSON(data: data!)
                        let route = swiftyJSON["routes"].array
                        let routeDirection = route![0].dictionary
    
                        let placeInfo = routeDirection!["overview_polyline"]!.dictionaryValue
    
                        let points = placeInfo["points"]?.string
                        let path = GMSPath(fromEncodedPath: points!)
                        let pathLine = GMSPolyline(path: path)
                        pathLine.strokeColor = UIColor.blueColor()
                        pathLine.strokeWidth = 6
                        pathLine.map = self.GoogleMaps
                    }
                }
                task.resume()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-03-27
      • 1970-01-01
      • 1970-01-01
      • 2021-02-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多