Google Elevation API: Encoded polyline

567 Views Asked by At

Is it possible to consume the google Elevation API with an encoded polyline through the client?

I know there is

https://maps.googleapis.com/maps/api/elevation/json?key=" + Meteor.settings.public.googleMaps + "&locations=enc:" + encodedPath

But this does not work over client side, only server side. Or am I mistaken?

I cannot seem to get this to work through the elevator object.

elevator.getElevationAlongPath({
   path: L.PolylineUtil.encode(path),
   samples: 256,
}, function(elevations, status) {

nor

 elevator.getElevationForLocations({
   locations: L.PolylineUtil.encode(batch)
 },

Error message is:

in property locations: not an Array

It works with an array of LatLng's, but that would be too inefficient for my application, since I need the elevation along a path of 1000s of coordinates.

1

There are 1 best solutions below

0
On

You can use the google.maps.geometry.encoding.encodePath(path:Array<LatLng>|MVCArray<LatLng>) method it takes an array of latLngs and encodes them into a polyline

var polyline = google.maps.geometry.encoding.encodePath(yourLatlangArray);

https://maps.googleapis.com/maps/api/elevation/json?key=" + 
Meteor.settings.public.googleMaps + "&locations=enc:" + polyline