ios - 获取两个位置之间的路点

标签 ios google-maps google-api google-directions-api

我正在尝试开发一个类似于 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/

相关文章:

ios - 在 UITableViewCell 中添加自定义编辑和删除按钮

java - 最后一个已知位置是在多长时间前记录的?

javascript - 将 "this"传递给在类中实例化的类

java - 导入 com.google.api.services.samples.youtube.cmdline.Auth;

javascript - 使用 BigQuery API 客户端时的授权

ios - 在应用商店或 Paypal 或其他地方?

ios - card.io 库与 Xcode 6.3 (iOS) 链接错误

ios - (Swift + Firebase) 将 observeSingleEvent 转换为观察 .childAdded

android - 如何捕捉 map 平移 |使用 Android SDK 缩放完成事件?

google-app-engine - Google Cloud Datastore 控制台 - 服务不可用 503