简体   繁体   English

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

[英]How to Add Snap to Roads Google Map in Android Studio

Hello I would like to ask how to add Snap to Road when I have the route given by google map API. 您好,当我拥有Google Map API给出的路线时,我想问一下如何添加对齐道路。 I have a bunch of Lat lang from point A line to point B line and draw a lines like Polylines, but what i want is how to add this code snap to Road from given route? 我有一束Lat lang从A点线到B点线,并绘制了一条类似Polylines的线,但是我想要的是如何从给定路线将此代码捕捉添加到Road? this is how to add more points from the Point A to Point B, here is what i want to add, https://developers.google.com/maps/documentation/roads/snap 这是从A点到B点添加更多点的方法,这就是我要添加的内容, https://developers.google.com/maps/documentation/roads/snap

my project is look like this 我的项目看起来像这样 在此处输入图片说明

  1. Get overview_polyline by Json and Gson (should use https://maps.googleapis.com/maps/api/directions/json?origin=...&destination=place_id:...&mode=DRIVING&key=.. .) 获取Json和Gson的overview_polyline(应使用https://maps.googleapis.com/maps/api/directions/json?origin=...&destination=place_id:...&mode=DRIVING&key= ..。
  2. Decode it to List by function 将其解码为按功能列出

     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.Add to map: 3.添加到地图

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM