【发布时间】:2016-06-08 03:32:33
【问题描述】:
从 AnyLocation 到 MyCurrentLocation 获取 ETA(预计到达时间)的正确方法是什么?
我想,当点击任何注释时,我必须根据该注释和用户的当前位置在页脚上设置详细信息。
请看下图更好地理解。
我看到了这个What is proper way to get ETA (estimated time arrival) from any location to my current location 和这个calculate time taken to cover a journey in Apple Maps 但是他们并没有用这个解决我的问题。使用这个我总是得到空响应。我把我的代码放在下面:-
double latitude = -0.075410;
double longitude = 51.512520;
MKPlacemark *placemark = [[MKPlacemark alloc] initWithCoordinate:CLLocationCoordinate2DMake(latitude, longitude) addressDictionary:nil] ;
MKMapItem *mapItemSource = [[MKMapItem alloc] initWithPlacemark:placemark];
double latitude1 = -0.132128;
double longitude1 = 51.464138;
MKPlacemark *placemark1 = [[MKPlacemark alloc] initWithCoordinate:CLLocationCoordinate2DMake(latitude1, longitude1) addressDictionary:nil] ;
MKMapItem *mapItemDestination = [[MKMapItem alloc] initWithPlacemark:placemark1];
MKDirectionsRequest *directionsRequest = [[MKDirectionsRequest alloc] init];
[directionsRequest setSource:mapItemSource];
[directionsRequest setDestination:mapItemDestination];
directionsRequest.transportType = MKDirectionsTransportTypeAutomobile;
MKDirections *directions = [[MKDirections alloc] initWithRequest:directionsRequest];
[directions calculateETAWithCompletionHandler:^(MKETAResponse *response, NSError *error) {
if (error) {
NSLog(@"Error %@", error.description);
} else {
NSLog(@"expectedTravelTime %f", response.expectedTravelTime);
}
}];
//I am not sure why I am getting Null response into calculateETAWithCompletionHandler this method..
//Also tried following......
[directions calculateDirectionsWithCompletionHandler:^(MKDirectionsResponse *response, NSError *error) {
if (error) {
NSLog(@"Error %@", error.description);
} else {
MKRoute * routeDetails = response.routes.lastObject;
//[self.mapView addOverlay:routeDetails.polyline];
NSLog(@"Street %@",[placemark.addressDictionary objectForKey:@"Street"]);
NSLog(@"distance %@",[NSString stringWithFormat:@"%0.1f Miles", routeDetails.distance/1609.344]);
NSLog(@"expectedTravelTime %@",[NSString stringWithFormat:@"%0.1f minutes",routeDetails.expectedTravelTime/60]);
}
}];
//I am not sure why I am getting Null response into calculateDirectionsWithCompletionHandler this method..
我还看到了这个Is there any way to determine the driving time between two locations using Apple's Maps API? 和这个How to calculate time required to complete the path in between two locations?。但是现在,我不想使用Google Maps Directions API。因为我的客户不想使用它。如果 Google API 是免费的,那我当然更喜欢它。
另外,我尝试了distanceFromLocation 方法。但是,我认为,这个解决方案假设两点之间的距离是直线,这几乎没有用处。
有没有其他解决方案可以做到这一点..??
任何帮助将不胜感激。
【问题讨论】:
-
您是否假设您的用户启用了
noclip作弊码?如果是这样,那么计算只是位置之间的直线距离,除以它们的平均步行距离。否则,您需要地图数据。 -
@JonathonReinhart,哈哈。你能告诉我如何启用该作弊吗?这可能非常有用。
-
这个问题太宽泛了。您发布了几个链接并说“但他们并没有解决我的问题。” (原文如此)。他们是如何未能满足您的需求的,特别是?
-
@Duncan :我多次尝试了这个答案,但总是得到空值。我提到了这些链接,因为我想展示我之前尝试过的内容。否则,您说过,这个问题与这些问题重复。
标签: ios objective-c google-maps durandal directions