1

I'm using google elevation service

I want to fetch data for my path, which consists of about 1k points. I know that I cannot sent them all in query divided by | separator, because I would exceed request size limit, so I'm encoding those points as it is mentioned in docs by Encoded Polyline Algorithm and send them like:

https://maps.googleapis.com/maps/api/elevation/json?key=KEY&path=cgg%7EE%7C%7B%7EpUfcaAwe%7CG&samples=3

Points: 36.578581,-118.291994|36.23998,-116.83171

Points encoded: cgg~E|{~pUfcaAwe|G

Points encoded + urlencoded: cgg%7EE%7C%7B%7EpUfcaAwe%7CG

But I'm getting the following error message:

Invalid request. Invalid 'path' parameter..

When I ask google with non encoded query (path separated by pipe separator) I receive proper data.

Do you have some hints what I am doing wrong in here?

2
  • 1
    Im not seeing any php code here why is this tagged php? Did you forget to add some code? Commented Mar 4, 2021 at 9:08
  • 1
    @DaImTo acutally it is not connected with PHP, sorry. Commented Mar 4, 2021 at 9:11

1 Answer 1

2

The path parameter expects your encoded points to be prefixed with enc:

This is not super clear from the documentation, I must admit.

With your encoded points cgg~E|{~pUfcaAwe|G the path parameter would become:

path=enc:cgg~E|{~pUfcaAwe|G

Proof of concept:

https://maps.googleapis.com/maps/api/elevation/json?key=YOUR_API_KEY&path=enc:cgg~E|{~pUfcaAwe|G&samples=3

You must replace YOUR_API_KEY with your own key.

This returns the following:

{
   "results" : [
      {
         "elevation" : 4411.8828125,
         "location" : {
            "lat" : 36.57858,
            "lng" : -118.29199
         },
         "resolution" : 19.08790397644043
      },
      {
         "elevation" : 1372.885498046875,
         "location" : {
            "lat" : 36.41150237848279,
            "lng" : -117.5602587614725
         },
         "resolution" : 9.543951988220215
      },
      {
         "elevation" : -84.51690673828125,
         "location" : {
            "lat" : 36.23998,
            "lng" : -116.83171
         },
         "resolution" : 9.543951988220215
      }
   ],
   "status" : "OK"
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.