Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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. - I got from another device its location (lon/lat) and want to when the other person will pick me up... In this case what web-service can I use to get this info for the user? Does mapkit provides that kind of option?

b. In case it will be done on the server-side and I'll just send my user location, what are the tools my server-side programmer can use to get ETA info in order to send it back to my user?

Thank you all in advance.

I saw this: Is there any way to determine the driving time between two locations using Apple's Maps API? - the problem, as I found in other places, (to my understanding)is that google api requires use of Google Maps app that isn't installed on every iOS user now.

like image 729
MatanGold Avatar asked Sep 02 '13 17:09

MatanGold


People also ask

How do you calculate time of arrival ETA?

ETA is purely a statistical term and based on simple formula i.e. Time (ETA) is equal to distance divided by speed of travel, transportation. This small concept is very useful in business planning and management.

How do you calculate estimated time of arrival for shipment?

Actually, it is pretty simple: time equals total distance divided by average speed.

How is ETA calculated in different time zones?

Translate the Zone Time and Date of Departure Port to GMT and Date of Departure. Calculate the elapsed time of the voyage, including layovers, and apply it to GMT of Departure to find the GMT and Date of Arrival. Apply the reversed ZD (Zone Description) of the Arrival Port to GMT to find the ZT and Date of Arrival.


2 Answers

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
        }
    }];
like image 124
M to the K Avatar answered Sep 28 '22 20:09

M to the K


This worked for me using route.distance from M to the K's answer I was modifying code from this tutorial 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;


            }
        }

    }];
}
like image 32
Hblegg Avatar answered Sep 28 '22 21:09

Hblegg