获取两个位置之间的路线点

Amr*_*dhu 5 google-maps google-api ios google-directions-api

我试图开发一个与应用类似的iOS 应用。

我需要计算两个城市或两个位置之间的中间位置。我不知道哪个API是最好的。我尝试了Google Directions API。但这并不提供两个位置之间的位置。谁能建议一个API。我需要尽快实施。

谢谢

chi*_*hah 4

您需要使用api 来获取两个位置和城市之间的路线

当你触发这个 api 时,你会在这个字典中得到编码的折线对象

overview_polyline: {
points: "m_qkCknuyLiIgEeAw@gA_A{HgGs@i@i@|@m@jAuCdGa@z@QRy@pBYXa@t@BBf@b@tE`Aa@lJKjA?P"
},
Run Code Online (Sandbox Code Playgroud)

类似上面的东西,它是两点之间的纬度和经度的编码格式

您可以通过以下方法获取经纬度数组

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];
}
Run Code Online (Sandbox Code Playgroud)