SwiftyJSon - Call可以抛出,但是没有标记为'尝试'并且不处理错误

时间:2018-06-01 17:53:41

标签: ios swift xcode google-maps

我正在构建一个项目,要求我使用谷歌地图,但我遇到了一个错误。我将firebase添加到项目后突然出现此错误,即使在删除firebase后也拒绝离开。我尝试过使用

let json =  try! JSON(data: response.data!)

但它只会使错误静音并显示没有仍然无用的路线的地图。我已经检查过堆栈溢出以用于以前的解决方案但它们不适合我,因为它没有解决在最终加载时不在地图上显示路径的问题。以下是错误即将发生的函数示例。

func drawPath(startLocation: CLLocation, endLocation: CLLocation)
{
    let origin = "\(startLocation.coordinate.latitude),\(startLocation.coordinate.longitude)"
    let destination = "\(endLocation.coordinate.latitude),\(endLocation.coordinate.longitude)"


    let url = "https://maps.googleapis.com/maps/api/directions/json?origin=\(origin)&destination=\(destination)&mode=driving"

    Alamofire.request(url).responseJSON { response in

        print(response.request as Any)  // original URL request
        print(response.response as Any) // HTTP URL response
        print(response.data as Any)     // server data
        print(response.result as Any)   // result of response serialization

        let json =   JSON(data: response.data!)
        let routes = json["routes"].arrayValue

        // print route using Polyline
        for route in routes
        {
            let routeOverviewPolyline = route["overview_polyline"].dictionary
            let points = routeOverviewPolyline?["points"]?.stringValue
            let path = GMSPath.init(fromEncodedPath: points!)
            let polyline = GMSPolyline.init(path: path)
            polyline.strokeWidth = 4
            polyline.strokeColor = UIColor.black
            polyline.map = self.googleMaps
        }

    }


}

这可能只是我不知道的事情,所以我需要有人指出我做得不对。

0 个答案:

没有答案