Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - Polyline encoding algorithm?

In my android project I have List of GeoPoints. I have a algorithm to decode the encoded polyline string. Can anyone help me for encoding the List of GeoPoints to polyline string in-order to save this in Shared Preferences.

like image 875
SomeswarReddy Avatar asked Apr 30 '12 07:04

SomeswarReddy


3 Answers

For Java generally, the official Google Maps Services for Java library has a utility, too.

PolylineEncoding.decode(String);
PolylineEncoding.encode(List<LatLng>); // Note that this is not the Android LatLng

Code is here.

like image 107
Mark McDonald Avatar answered Oct 05 '22 15:10

Mark McDonald


you should include the new googlemaps utils library for Android and then use PolyUtil:

PolyUtil.encode(latLngPath)
PolyUtil.decode(encodedPath)
like image 36
Chiara Avatar answered Oct 05 '22 13:10

Chiara


From Google:

http://groups.google.com/group/google-maps-api/browse_thread/thread/c85319eb7fd930dc

Seems like an Java Polyline impl. in progress.

From Github:

https://github.com/markrambow/JavaPolylineEncoder

https://github.com/petpen/JavaPolylineEncoder2

And the spec is here:

https://developers.google.com/maps/documentation/utilities/polylinealgorithm

like image 34
Thomas Dignan Avatar answered Oct 05 '22 14:10

Thomas Dignan