我正在尝试在Google地图中显示从一个地方到另一个地方的路径,而我得到的是这样的东西。但我需要表现出像这样。这意味着整个路径需要根据地图上的路径显示和显示,缩放级别应调整
这是我尝试从API绘制路径的代码。在这里let settingCam设置摄像机以调整到其中一个位置
func showingPathFromPickupLocToDropLoc(dropLat: Double, dropLong: Double){
let origin = "\(dropLat),\(dropLong)"
let destination = "\(dropLatitude),\(dropLongitude)"
let settingCam: CLLocationCoordinate2D = CLLocationCoordinate2D(latitude: CLLocationDegrees(dropLat), longitude: CLLocationDegrees(dropLong))
let url = URL(string: "https://maps.googleapis.com/maps/api/directions/json?origin=\(origin)&destination=\(destination)&key=\(NEWAPI.GOOGLE_APIKEY)")
URLSession.shared.dataTask(with: url!, completionHandler: {(data, response, error) in
if(error != nil){
print("error")
}else{
do{
let json = try JSONSerialization.jsonObject(with: data!, options:.allowFragments) as! [String : AnyObject]
if json["status"] as! String == "OK"{
let routes = json["routes"] as! [[String:AnyObject]]
OperationQueue.main.addOperation({
for route in routes{
let routeOverviewPolyline = route["overview_polyline"] …Run Code Online (Sandbox Code Playgroud) google-maps google-maps-api-3 google-maps-markers google-maps-sdk-ios swift