Reputation: 7014
My application is java google map web application. Get 2 points and send to Google
http://maps.googleapis.com/maps/api/directions/json?origin="+saddr+"&destination="+daddr+"&sensor=false
, it give json. Then I have decodeoverview_polyline
. My Problem is sometime it give extended value.
This is my decode part.
public static ArrayList<Location> decodePoly(String encoded) {
ArrayList<Location> poly = new ArrayList<Location>();
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;
Location p = new Location((((double) lat / 1E5)),
(((double) lng / 1E5)));
// System.out.println("==p==" +p.getLatitude());
// System.out.println("==p==" +p.getLongitude());
poly.add(p);
}
return poly;
}
The black color mark , the rep didn't travel to that path. But it drawn like that.
http://maps.googleapis.com/maps/api/directions/json?origin=6.95522,79.8864&destination=6.96165,79.8958&sensor=false
This overview_polyline
is _pmi@}xqfNEkEM{@DREUOc@Wi@MOkBmCi@k@o@o@gA}@qD_DiDgD{MoN_DeDJEVGvBS
this 2nd wrong path drawn
This is my db sample data...
Please give some idea? What is an issue?
Thanks in advance.
Upvotes: 1
Views: 1197
Reputation: 1037
Probably this is just an error for the smooth applied to the points, as described in the documentation:
overview_polyline contains an object holding an array of encoded points that represent an approximate (smoothed) path of the resulting directions.
I actually saw how my path is drawed twice, so the last point connects with the first one, making a close path.
I guess that this element in the call output is just for a far-zoom use or something similar.
However, you can still parse the rest of the content as described in this post.
Upvotes: 1