gpt4 book ai didi

ios - map 方向线未显示在 map 上

转载 作者:行者123 更新时间:2023-11-28 07:50:49 25 4
gpt4 key购买 nike

试图给出用户位置与定义位置之间的方向线。精确定位是正确的,并且恰好位于所需位置,但没有将用户位置引导至定义位置的“线”方向。

它是这样完成的:

enter image description here

以及我绘制 map 以及解析 google maps API JSON 的代码:

func DrawDirection(url: String, cord: CLLocationCoordinate2D){
request(url).responseJSON { response in
let parsed = try? JSONSerialization.jsonObject(with: response.data!, options: []) as! [String:Any]
let routes = parsed!["routes"] as! [[String:Any]]
for route in routes {
let dictArr = route["legs"] as? [[String:Any]]
let dict = dictArr![0]["steps"] as? [[String:Any]]
let start = dict![0]["start_location"] as? [String:Any]
let lat = start!["lat"] as! Double
let long = start!["lng"] as! Double
let dotcoordinate = CLLocationCoordinate2D(latitude: CLLocationDegrees(lat), longitude: CLLocationDegrees(long))
let routePoly = route["overview_polyline"] as! [String:Any]
let points = routePoly["points"] as! String
let line = points
DispatchQueue.main.async {
let bounds = GMSCoordinateBounds(coordinate: cord, coordinate: dotcoordinate)
let update = GMSCameraUpdate.fit(bounds, with: UIEdgeInsetsMake(170, 30, 30, 30))
self.CinemaLoc.moveCamera(update)
}
self.AddingPolyLine(encString: line, dir: cord, dot: dotcoordinate)
}
}
}

func AddingPolyLine(encString: String, dir: CLLocationCoordinate2D, dot: CLLocationCoordinate2D){
let dotpath: GMSMutablePath = GMSMutablePath()
dotpath.add(CLLocationCoordinate2DMake(dir.latitude, dir.longitude)) //original loc
dotpath.add(CLLocationCoordinate2DMake(dot.latitude, dot.longitude)) //starting points
let dotpoly = GMSPolyline(path: dotpath)
dotpoly.map = self.CinemaLoc
dotpoly.strokeWidth = 3.0
let styles:[Any] = [GMSStrokeStyle.solidColor(.blue), GMSStrokeStyle.solidColor(.clear)]
let lengths:[Any] = [10,5]
dotpoly.spans = GMSStyleSpans(dotpoly.path!,styles as!
[GMSStrokeStyle], lengths as! [NSNumber], GMSLengthKind.rhumb)
let poly = GMSPolyline(path: dotpath)
poly.strokeWidth = 3.0
poly.strokeColor = .red
poly.map = self.CinemaLoc
}

cord 是用户位置

一直在尝试所有可能的堆栈溢出方法,但没有得到任何改变,有时会有日志说“无法在路径 ~/GoogleMaps.bundle/GMSCacheStorage.momd/加载优化模型”

我的代码有问题吗?

最佳答案

对于特定路径,路径应该只创建一次,然后您可以向路径添加坐标。将 let dotpath: GMSMutablePath = GMSMutablePath() 放在方法调用中是错误的,每个循环都会调用它。

关于ios - map 方向线未显示在 map 上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49767339/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com