我想使用此库将谷歌地图用作路由器。
https://github.com/poulpix/PXGoogleDirections
我的api密钥:
AIzaSyAHQPNUQuSYLUsa3JxVxTyUH_Lab-7EPxc
我从这个链接获得了这个api密钥:
https://console.developers.google.com/apis/credentials
我的代码:
override func viewDidLoad() {
super.viewDidLoad()
initialValues()
let directionsAPI = PXGoogleDirections(apiKey: "AIzaSyAHQPNUQuSYLUsa3JxVxTyUH_Lab-7EPxc",
from: PXLocation.coordinateLocation(CLLocationCoordinate2DMake(37.331690, -122.030762)),
to: PXLocation.specificLocation("Googleplex", "Mountain View", "United States"))
directionsAPI.calculateDirections({ response in
switch response {
case let .error(_, error):
// Oops, something bad happened, see the error object for more information
print("errorrrr \(error)")
break
case let .success(request, routes):
// Do your work with the routes object array here
print("ok map")
break
}
})
}
我的错误:
errorrrr Error Domain=PXGoogleDirectionsErrorDomain Code=6 "The service denied use of the directions service by this application" UserInfo={NSLocalizedDescription=The service denied use of the directions service by this application}
另一个问题,如果我的密钥工作正常,地图会显示在哪里?我认为它需要一个空的view
。