What is proper way to get ETA (estimated time arrival) from any location to my current location

前端 未结 2 547
陌清茗
陌清茗 2021-01-02 10:26

Would like to know what is proper way to get ETA (estimated time arrival) from any location to my current location, in consideration the following situation:

a. ex.

2条回答
  •  没有蜡笔的小新
    2021-01-02 10:57

    I know this post is a bit old but in case someone is looking at the answer since iOS 7 Apple provide an API in MapKit in order to calculate all these info.

    Here is a snippet of how to use this API

        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
            }
        }];
    

提交回复
热议问题