栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

使用Google Directions API的Map View绘制路线-解码折线

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

使用Google Directions API的Map View绘制路线-解码折线

我有一个可以为您解码它们的类,在下面添加该类,然后像这样调用您的代码:

int[] depredZoomLevels = PolylineDeprer.depreZoomLevels(levels);GeoPoint[] gPts = PolylineDeprer.deprePoints(points, depredZoomLevels.length);

您从JSON响应中提取的数据在哪里

points
levels
。然后,您可以遍历一系列地理点,在它们之间画一条线以显示方向。

希望这可以帮助!肯尼


编辑:似乎Google Directions
API不再将缩放级别字符串作为JSON响应的一部分返回,不过不用担心,我们使用的唯一目的就是检查点数,因此我们可以简单地将它们放入像这样的列表:

public static List <GeoPoint> deprePoints(String enpred_points){int index = 0;int lat = 0;int lng = 0;List <GeoPoint> out = new ArrayList<GeoPoint>();try {    int shift;    int result;    while (index < enpred_points.length()) {        shift = 0;        result = 0;        while (true) { int b = enpred_points.charAt(index++) - '?'; result |= ((b & 31) << shift); shift += 5; if (b < 32)     break;        }        lat += ((result & 1) != 0 ? ~(result >> 1) : result >> 1);        shift = 0;        result = 0;        while (true) { int b = enpred_points.charAt(index++) - '?'; result |= ((b & 31) << shift); shift += 5; if (b < 32)     break;        }        lng += ((result & 1) != 0 ? ~(result >> 1) : result >> 1);                out.add(new GeoPoint((lat*10),(lng*10)));    }    return out;}catch(Exception e) {    e.printStackTrace();}return out;}

编辑:旧代码

public class PolylineDeprer {public static GeoPoint[] deprePoints(String enpred_points, int countExpected){    int index = 0;    int lat = 0;    int lng = 0;    int cnt = 0;    GeoPoint[] out = new GeoPoint[countExpected];    try {        int shift;        int result;        while (index < enpred_points.length()) { shift = 0; result = 0; while (true) {     int b = enpred_points.charAt(index++) - '?';     result |= ((b & 31) << shift);     shift += 5;     if (b < 32)         break; } lat += ((result & 1) != 0 ? ~(result >> 1) : result >> 1); shift = 0; result = 0; while (true) {     int b = enpred_points.charAt(index++) - '?';     result |= ((b & 31) << shift);     shift += 5;     if (b < 32)         break; } lng += ((result & 1) != 0 ? ~(result >> 1) : result >> 1);  out[cnt++] = new GeoPoint((lat*10),(lng*10));        }        return out;    }catch(Exception e) {        e.printStackTrace();    }    return out;}public static int[] depreZoomLevels(String enpredZoomLevels){    int[] out = new int[enpredZoomLevels.length()];    int index = 0;    for(char c : enpredZoomLevels.toCharArray())        out[index++] = c - '?';    return out;}}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/449187.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号