SomeswarReddy
SomeswarReddy

Reputation: 123

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.

Upvotes: 6

Views: 9835

Answers (4)

shubomb
shubomb

Reputation: 832

Added this library work for me :

implementation 'com.google.maps:google-maps-services:2.2.0'

PolylineEncoding.decode(String);
PolylineEncoding.encode(List<LatLng>); 

Upvotes: 0

Mark McDonald
Mark McDonald

Reputation: 8190

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.

Upvotes: 5

Chiara
Chiara

Reputation: 1887

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

PolyUtil.encode(latLngPath)
PolyUtil.decode(encodedPath)

Upvotes: 15

Related Questions