问题描述
我正在尝试在适用于Android的MapsV2中的多义线周围放置一个缓冲区,但我还没有找到方法,我正在考虑在该多义线周围绘制多边形,但还没有发现任何这样做的人,有可能吗?
I am trying to put a buffer around a polyline in MapsV2 for android but I haven't find how to do it yet, I was thinking on drawing a polygon around the polyline but also haven't found anyone that have done that, is it possible?
推荐答案
( https://maps.googleapis.com/maps/api/directions/json?origin=75+9th+ Ave + New + York,+ NY& Destination = MetLife + Stadium + 1 + MetLife + Stadium + Dr + East + Rutherford,+ NJ + 07073& key = YOUR_API_KEY ),您将获得一个 overview_polyline strong> jsonObject,从此处获取编码点,并使用此方法对其进行解码:
in Google's directions api (https://maps.googleapis.com/maps/api/directions/json?origin=75+9th+Ave+New+York,+NY&destination=MetLife+Stadium+1+MetLife+Stadium+Dr+East+Rutherford,+NJ+07073&key=YOUR_API_KEY ) you get one overview_polyline jsonObject,get encoded points From here, and decode it using this method:
private List<LatLng> decodePoly(String encoded) {
List<LatLng> poly = new ArrayList<>();
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;
}
您会获得经纬度列表,现在,使用google map的 getMapAsync 方法将此latlng添加到您的地图中:
You get List of latitude and longitude,now, using google map's getMapAsync Method add this latlng in your map :
googleMap.addPolyline(new PolylineOptions().geodesic(true).addAll(latLngList));
这篇关于如何在Android中缓冲折线或在折线周围绘制多边形?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!