我在我的 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/