【问题标题】:How to Add Snap to Roads Google Map in Android Studio如何在 Android Studio 中添加捕捉到道路谷歌地图
【发布时间】:2016-05-30 01:27:13
【问题描述】:

您好,我想问一下当我有 google map API 给出的路线时如何将 Snap 添加到 Road。 我有一堆从 A 点线到 B 点线的 Lat lang 并绘制一条像折线这样的线,但我想要的是如何将此代码从给定路线添加到 Road? 这是如何将更多点从 A 点添加到 B 点, 这是我要补充的, https://developers.google.com/maps/documentation/roads/snap

我的项目是这样的

【问题讨论】:

  • 你试过读这个吗? stackoverflow.com/questions/10513360/…
  • 是的,但我认为它是相同的,我已经测试了 snap to road,但这些点给出了我需要的相同点,所以我认为它没用

标签: java google-maps android-studio snapshot


【解决方案1】:
  1. 通过 Json 和 Gson 获取 overview_polyline(应使用 https://maps.googleapis.com/maps/api/directions/json?origin=...&destination=place_id:...&mode=DRIVING&key=..。)
  2. 按函数将其解码为列表

    public List<LatLng> decodePoly(String encoded) {
    // encoded is overview_polyline.points; 
    List<LatLng> poly = new ArrayList<LatLng>();
    int 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;
            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.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.添加到地图:

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

【讨论】:

  • 如何获取编码字符串?我能够以字符串形式获得响应....但无法获得 overview_polyline 点?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-07-16
  • 1970-01-01
  • 2018-07-20
  • 2012-05-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多