【问题标题】:What is proper way to get ETA (estimated time arrival) from any location to my current location从任何位置到我当前位置的 ETA(预计到达时间)的正确方法是什么
【发布时间】:2013-09-02 17:17:59
【问题描述】:

想知道从任何位置到我当前位置的 ETA(预计到达时间)的正确方法是什么,考虑到以下情况:

一个。前任。 - 我从另一台设备获得了它的位置(经度/纬度),并且想知道其他人何时接我......在这种情况下,我可以使用什么网络服务来为用户获取此信息? mapkit 是否提供这种选项?

b.如果它将在服务器端完成并且我只发送我的用户位置,我的服务器端程序员可以使用哪些工具来获取 ETA 信息以便将其发送回我的用户?

提前谢谢大家。

我看到了这个:Is there any way to determine the driving time between two locations using Apple's Maps API? - 我在其他地方发现的问题(据我了解)是 google api 需要使用现在并非每个 iOS 用户都安装的 Google Maps 应用程序。

【问题讨论】:

  • 你应该看看 iOS 7 中的一些新的 SDK API。

标签: ios objective-c google-maps map mapkit


【解决方案1】:

我知道这篇文章有点老了,但如果有人正在寻找答案,因为 iOS 7 Apple 在 MapKit 中提供了一个 API 来计算所有这些信息。

这里是如何使用这个 API 的 sn-p

    MKDirectionsRequest *request = [[MKDirectionsRequest alloc] init];
    [request setSource:[MKMapItem mapItemForCurrentLocation]];
    [request setDestination:destination];
    [request setTransportType:MKDirectionsTransportTypeAutomobile];
    [request setRequestsAlternateRoutes:NO];
    MKDirections *directions = [[MKDirections alloc] initWithRequest:request];
    [directions calculateDirectionsWithCompletionHandler:^(MKDirectionsResponse *response, NSError *error) {
        if ( ! error && [response routes] > 0) {
            MKRoute *route = [[response routes] objectAtIndex:0];
            //route.distance  = The distance
            //route.expectedTravelTime = The ETA
        }
    }];

【讨论】:

  • 这种方法有效吗?在我的情况下,它在任何时间都返回 0.00...你能帮我解决这个问题吗?
  • 始终使用firstObject 而不是objectAtIndex:0。它的防撞功能更清晰
  • 谢谢你。我使用另一个函数来格式化结果。
  • 但是这个 ETA 在美国以外的地方从来没有用过。我正在为中国尝试它,每次它都没有找到任何方向:(有人可以对此有所了解吗,目前哪些国家和所有国家都支持 ETA 功能?
【解决方案2】:

这对我使用从 M 到 K 答案的 route.distance 有用 我正在修改本教程中的代码map directions tutorial

(IBAction)routeButtonPressed:(UIBarButtonItem *)sender {
    MKDirectionsRequest *directionsRequest = [[MKDirectionsRequest alloc] init];
    MKPlacemark *placemark = [[MKPlacemark alloc] initWithPlacemark:thePlacemark];
    [directionsRequest setSource:[MKMapItem mapItemForCurrentLocation]];
    [directionsRequest setDestination:[[MKMapItem alloc] initWithPlacemark:placemark]];
    directionsRequest.transportType = MKDirectionsTransportTypeAutomobile;
    MKDirections *directions = [[MKDirections alloc] initWithRequest:directionsRequest];
    [directions calculateDirectionsWithCompletionHandler:^(MKDirectionsResponse *response, NSError *error) {
        if (error) {
            NSLog(@"Error %@", error.description);
        } else {
            routeDetails = response.routes.lastObject;
            [self.mapView addOverlay:routeDetails.polyline];
            self.destinationLabel.text = [placemark.addressDictionary objectForKey:@"Street"];
            self.distanceLabel.text = [NSString stringWithFormat:@"%0.1f Miles", routeDetails.distance/1609.344];

            self.etaLabel.text = [NSString stringWithFormat:@"%0.1f minutes",routeDetails.expectedTravelTime/60];

            //self.transportLabel.text = [NSString stringWithFormat:@"%u" ,routeDetails.transportType];
            self.allSteps = @"";
            for (int i = 0; i < routeDetails.steps.count; i++) {
                MKRouteStep *step = [routeDetails.steps objectAtIndex:i];
                NSString *newStep = step.instructions;
                self.allSteps = [self.allSteps stringByAppendingString:newStep];
                self.allSteps = [self.allSteps stringByAppendingString:@"\n\n"];
                self.steps.text = self.allSteps;


            }
        }

    }];
}

【讨论】:

  • 成功了吗?在我的情况下,它返回 0.00 你能帮忙吗
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-09-22
  • 1970-01-01
  • 2011-07-24
  • 2021-01-28
相关资源
最近更新 更多