ios - GoogleMaps iOS - 获取直线而不是路线

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

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

有人可以帮忙吗?

最佳答案

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

在您有一个从 Google API 方向获取方向的 url 之后。您执行以下操作(我使用了 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()

关于ios - GoogleMaps iOS - 获取直线而不是路线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36461095/

相关文章:

ios - Swift UICollectionView Cells 移动/UIButton 标签在 ReloadData 上闪烁

iphone - 谷歌驱动器直接链接到文件

angularjs - 在angularjs中使用ngMap模块es6类时,使用 'this'时 'places-auto-complete'未绑定(bind)到构造函数

javascript - Geocoder - IE8 中的编码问题

javascript - NodeJs Express 路线不工作

ruby-on-rails-3.2 - Rails 3.2 路由 : multiple defaults

iphone - 从 plist 的数据加载给我错误顺序的值

iOS:引用核心图标例如:搜索放大镜?

javascript - map 已经创建时如何设置谷歌地图背景。 map.setOptions() 不起作用

ruby - Sinatra 路由的必需和可选参数