我很奇怪!当我使用 origin1和 destinationA时不起作用
状态=“零结果”;
但是如果使用origin2和destinationB它工作得很好我错过了什么吗
var origin = "55.930385, -3.118425"
var destination = "50.087692, 14.421150"
override func viewDidLoad() {
super.viewDidLoad()
durationDestance(origin: origin, destination: destination, mode:"bicycling")
}
func durationDestance(origin: String, destination: String, mode:String) {
var urlString : String = "https://maps.googleapis.com/maps/api/distancematrix/json?origins=\(origin)&destinations=\(destination)&mode=\(mode)&key=AIzaSyAVOt9LLagNGSOI8O0ri1Sbahcl_q5AFYc";
urlString = urlString.addingPercentEncoding(withAllowedCharacters: .urlFragmentAllowed)!
let session = URLSession.shared
let url = URL(string:urlString)!
session.dataTask(with: url) { (data: Data?, response: URLResponse?, erorr: Error?) -> Void in
print("url: \(urlString)")
if let responseData = data {
do{
let json = try JSONSerialization.jsonObject(with: responseData, options: JSONSerialization.ReadingOptions.allowFragments);
print(json);
}
catch{
print("do not serialization :)");
}
}
}.resume();
}