Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get way Points between two locations

I was trying to develope an iOS app similar to this app.

I need to calculate the intermediate locations between two cities or two locations. I couldn't figure out which API was the best. I tried google directions API. But that donot provide locations between two locations. Can anyone suggest an API. I need to implement this in swift.

Thanks

like image 679
Amrit Sidhu Avatar asked Sep 25 '22 22:09

Amrit Sidhu


1 Answers

You need to use this api for get routes between two location and cities

when you fire this api you get encoded polyline object in this dictionary

overview_polyline: {
points: "m_qkCknuyLiIgEeAw@gA_A{HgGs@i@i@|@m@jAuCdGa@z@QRy@pBYXa@t@BBf@b@tE`Aa@lJKjA?P"
},

something like above, it is encode formate of the latitude and longitude which between two points

you can get the latitude and longitude array by below methods

NSInteger index = 0, len = encoded.length;
int lat = 0, lng = 0;
while (index < len) {
    int b, shift = 0, result = 0;
    do {
        //            b = encoded.charAt(index++) - 63;
        b = [encoded characterAtIndex:index++] - 63;
        result |= (b & 0x1f) << shift;
        shift += 5;
    } while (b >= 0x20);
    int dlat = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1));
    lat += dlat;
    shift = 0;
    result = 0;
    do {
        b = [encoded characterAtIndex:index++] - 63;
        result |= (b & 0x1f) << shift;
        shift += 5;
    } while (b >= 0x20);
    int dlng = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1));
    lng += dlng;
    CLLocation *loc = [[CLLocation alloc] initWithLatitude:((double) lat / 1E5) longitude:((double) lng / 1E5)];
    [arrLocation addObject:loc];
}
like image 188
chirag shah Avatar answered Oct 03 '22 17:10

chirag shah