3

我需要找到两个位置之间的行车距离。我不需要在地图中显示方向,只需要计算距离,我需要在我的应用程序中使用它。

MapKit 允许这样做吗?有没有可以使用的替代品?

我可以使用 CloudMade 进行地理编码,但似乎没有获得行驶距离的选项。

感谢任何帮助。

4

3 回答 3

3

CloudMade 还提供行车路线。如果您只对距离感兴趣,请忽略说明。

API 调用如下所示:

http://navigation.cloudmade.com/YOUR-API-KEY-GOES-HERE/api/0.3/47.25976,9.58423,47.26117,9.59882/car/shortest.js

并且 JSON 包括

....
route_summary: {
total_distance: Distance in meters,...

来源

于 2010-01-20T23:39:17.963 回答
2

在 Google Groups 中找到这个,有用吗?

http://groups.google.com/group/google-maps-api/msg/4dc2fad4f74e3314?pli=1

于 2010-05-05T03:40:44.720 回答
1

在我的应用程序中,我使用 MKDirections 来获取两个位置之间的驾驶(步行)距离。

CLLocationCoordinate2D startCoordinates = YOUR_START_COORDINATES;
CLLocationCoordinate2D endCoordinates = YOUR_END_COORDINATES;

MKPlacemark *startPoint = [[MKPlacemark alloc] initWithCoordinate:startCoordinates];
MKPlacemark *endPoint = [[MKPlacemark alloc] initWithCoordinate:endCoordinates];

MKMapItem *startItem = [[MKMapItem alloc] initWithPlacemark:startPoint];
MKMapItem *endItem = [[MKMapItem alloc] initWithPlacemark:endPoint];

MKDirectionsRequest *request = [[MKDirectionsRequest alloc] init];

request.source = startItem;
request.destination = endItem;
request.transportType = MKDirectionsTransportTypeAutomobile; //here you can choose a transport type you need

MKDirections *direction = [[MKDirections alloc] initWithRequest:request];

[direction calculateDirectionsWithCompletionHandler:^(MKDirectionsResponse * _Nullable response, NSError * _Nullable error) {

          if (response) {
              for (MKRoute *route in response.routes) {
                  NSLog(@"Distance : %f", route.distance);
              }
          }

 }];

如果你有你的位置作为地址,那么你可以使用 CLGeocoder 的方法,它会给你地址的纬度和经度

- (void)geocodeAddressString:(NSString *)addressString completionHandler:(CLGeocodeCompletionHandler)completionHandler;

如果您将使用 MKDirections 的行驶距离结果与使用 Google 地图的行驶距离结果进行比较,您会发现它们有所不同。我正在搜索这件事并发现了以下链接http://www.macworld.co.uk/review/reference-education/apple-maps-vs-google-maps-3464377/

尽管苹果一直在改进他们的地图服务,但他们仍然向谷歌 (IMO) 承认了准确性,至少在有关行驶距离的问题上。因此,如果在您的情况下准确性不是很重要,那么您可以跟随 Apple。否则我会建议检查 Google API。

于 2017-07-29T11:20:53.863 回答