如何在Android Studio中将快照添加到Roads Google Map

如何在Android Studio中将快照添加到Roads Google Map,第1张

如何在Android Studio中将快照添加到Roads Google Map
  1. 获取Json和Gson的overview_polyline(应使用 https://maps.googleapis.com/maps/api/directions/json?origin=...&destination=place_id:...&mode=DRIVING&key=...)
  2. 将其解码为按功能列出
        public List<LatLng> deprePoly(String enpred) {    // enpred is overview_polyline.points;     List<LatLng> poly = new ArrayList<LatLng>();    int index = 0, len = enpred.length();    int lat = 0, lng = 0;    while (index < len) {        int b, shift = 0, result = 0;        do { b = enpred.charAt(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 = enpred.charAt(index++) - 63; result |= (b & 0x1f) << shift; shift += 5;        } while (b >= 0x20);        int dlng = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1));        lng += dlng;        LatLng p = new LatLng((((double) lat / 1E5)),     (((double) lng / 1E5)));        poly.add(p);    }    return poly;    }

3.Add to map:

        PolylineOptions polylineOptions= new PolylineOptions();    polylineOptions.addAll(deprePoly(overview_polyline.points));    mGoogleMap.addPolyline(polylineOptions.width(5).color(Color.BLUE).geodesic(false));


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5490741.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-12-12
下一篇2022-12-12

发表评论

登录后才能评论

评论列表(0条)

    保存