获取两个位置之间的路点
Get way Points between two locations
我正在尝试开发一个类似于 this 应用程序的 iOS 应用程序。
我需要计算两个城市或两个位置之间的中间位置。我不知道哪个 API 是最好的。我尝试了 google 个方向 API。但这不提供两个位置之间的位置。谁能推荐一个API。我需要在 swift.
中实现它
谢谢
您需要使用 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];
}
我正在尝试开发一个类似于 this 应用程序的 iOS 应用程序。
我需要计算两个城市或两个位置之间的中间位置。我不知道哪个 API 是最好的。我尝试了 google 个方向 API。但这不提供两个位置之间的位置。谁能推荐一个API。我需要在 swift.
中实现它谢谢
您需要使用 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];
}