用Swift计算ETA

我试图快速计算两个位置之间的估计旅行时间(步行),用户注释。

这是我目前的代码,它不会抛出任何程序崩溃的错误,但只返回“请求ETA时出错”

import UIKit import MapKit class LocationObjects: NSObject, MKAnnotation { /*let userView = CLLocation(latitude: mapView.centerCoordinate.latitude, longitude: mapView.centerCoordinate.longitude) let annotationPoint = CLLocation(latitude: annotation.coordinate.latitude, longitude: annotation.coordinate.longitude) let distance = userView.distance(from: annotationPoint)*/ var identifier = "bathroom location" var title: String? var coordinate: CLLocationCoordinate2D var distance: Double var phoneNumber: String var addressFinished: String var estimatedTravelTime: String // Request ETA function // Uses user location and destination to send request // For Estimated time of arrival class func requestETA(userCLLocation: CLLocation, coordinate: CLLocationCoordinate2D) -> String { var travelTime = String() let request = MKDirectionsRequest() /* Source MKMapItem */ let sourceItem = MKMapItem(placemark: MKPlacemark(coordinate: userCLLocation.coordinate, addressDictionary: nil)) request.source = sourceItem /* Destination MKMapItem */ let destinationItem = MKMapItem(placemark: MKPlacemark(coordinate: coordinate, addressDictionary: nil)) request.destination = destinationItem request.requestsAlternateRoutes = false // Looking for walking directions request.transportType = MKDirectionsTransportType.walking // You use the MKDirectionsRequest object constructed above to initialise an MKDirections object let directions = MKDirections(request: request) directions.calculateETA { (etaResponse, error) -> Void in if let error = error { print("Error while requesting ETA : \(error.localizedDescription)") travelTime = "Not Available" }else{ print("No error requesting ETA") travelTime = "\(Int((etaResponse?.expectedTravelTime)!/60)) min" } } return travelTime } init(name:String,lat:CLLocationDegrees,long:CLLocationDegrees,userCLLocation:CLLocation, phone:String, address:String){ title = name coordinate = CLLocationCoordinate2DMake(lat, long) distance = Double(String(format: "%.2f", (userCLLocation.distance(from: CLLocation(latitude: lat, longitude: long)))*0.000621371))! phoneNumber = phone addressFinished = address estimatedTravelTime = LocationObjects.requestETA(userCLLocation: userCLLocation, coordinate: coordinate) } } 

控制台看起来像这样一个非常长的行数

  2017-05-26 13:53:51.583 Toilet Locator[2568:181698] didFailWithError Error Domain=GEOErrorDomain Code=-3 "(null)" UserInfo={GEORequestThrottleStateLevel=0, GEORequestThrottleStateResetTimeRemaining=34.019131004810333} 2017-05-26 13:53:51.584 Toilet Locator[2568:181698] didFailWithError Error Domain=GEOErrorDomain Code=-3 "(null)" UserInfo={GEORequestThrottleStateLevel=0, GEORequestThrottleStateResetTimeRemaining=34.018206000328064} Error while requesting ETA : Directions Not Available Error while requesting ETA : Directions Not Available 

我希望得到一些指导,谢谢大家!

注意:ViewController调用这个类是连续进行多次,所以不知道这是否会导致苹果拒绝ETA请求?