我正在尝试在我的应用程序中计算 expectedTravelTime,但与 GoogleMaps 相比,我得到了不同的值。
这是我的代码:
NSArray *startLocationArray = [startLocation componentsSeparatedByString:@","];
NSArray *destinationArray = [destination componentsSeparatedByString:@","];
MKPlacemark *placemarkStartLocation = [[MKPlacemark alloc] initWithCoordinate:CLLocationCoordinate2DMake([startLocationArray[0] intValue],
[startLocationArray[1] intValue]) addressDictionary:nil];
MKMapItem *mapItemStartLocation = [[MKMapItem alloc] initWithPlacemark:placemarkStartLocation];
MKPlacemark *placemarkDestination = [[MKPlacemark alloc] initWithCoordinate:CLLocationCoordinate2DMake([destinationArray[0] intValue],
[destinationArray[1] intValue]) addressDictionary:nil];
MKMapItem *mapItemDestination = [[MKMapItem alloc] initWithPlacemark:placemarkDestination];
MKDirectionsRequest *request = [[MKDirectionsRequest alloc] init];
[request setSource:mapItemStartLocation];
[request setDestination:mapItemDestination];
[request setTransportType:MKDirectionsTransportTypeAutomobile];
[request setRequestsAlternateRoutes:NO];
MKDirections *directions = [[MKDirections alloc] initWithRequest:request];
__block MKRoute *route;
[directions calculateDirectionsWithCompletionHandler:
^(MKDirectionsResponse *response, NSError *error)
{
if ( ! error && [response routes] > 0)
{
route = [[response routes] objectAtIndex:0];
double exceedingTime = fmod(route.expectedTravelTime, 60);
eta = (route.expectedTravelTime - exceedingTime)/60;
int iEta = (int)eta;
lblEta.text = [NSString stringWithFormat:@"%im", iEta, nil];
}
}];
startLocation 和destination 在方法外传递,它们的值是:
startLocation = 37.776402,-122.408470
destination = 37.831287,-122.485519
我得到:
route.distance = 1513 (meters)
route.expectedTravelTime = 491 (should be seconds, so finally 8 minutes)
但在谷歌地图上,我得到了超过 30 分钟的预期旅行时间和超过 9 英里的距离
我哪里错了?