我正在尝试开发一个类似于 this 的 iOS 应用程序应用程序。
我需要计算两个城市或两个位置之间的中间位置。我不知道哪个 API 最好。我试过谷歌方向 API。但这不提供两个位置之间的位置。谁能推荐一个API。我需要快速实现。
谢谢
最佳答案
您需要使用 this用于获取两个位置和城市之间的路线的 api
当你触发这个 api 时,你会在这个字典中得到编码的折线对象
overview_polyline: {
points: "m_qkCknuyLiIgEeAw@gA_A{HgGs@i@i@|@m@jAuCdGa@z@QRy@pBYXa@t@BBf@b@tE`Aa@lJKjA?P"
},
类似上面,是两点之间经纬度的编码格式
可以通过以下方法获取经纬度数组
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];
}
关于ios - 获取两个位置之间的路点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34326659/