Nagarjuna Yelisetty
Nagarjuna Yelisetty

Reputation: 539

Google Static Maps show polyline using Encoded Route

I am trying to get the Google Map Static Image which show both origin,destination along with poly line using the Encoded Route data which I have but I was not able see anything on the map.

below is the link which I am using

`https://maps.googleapis.com/maps/api/staticmap?size=600x400&path=enc:i}cyHdpc@@?L?@bBAZERwHhNw@zBONULXbC}FjAwBh@eGbB[LGJW]gAmB_@w@_@w@_HnLgDrFqAhBSTQDMn@QfAcApF?^B\\Rl@z@xAL`@IR]RqA\\YF]@c@NcALWPWZeBbBuFdE}D~CuBlAgA~@c@\\OCy@b@eBb@_DpAuDjBw@n@]v@c@tBe@fBWj@k@d@mExByB|@qBpAYFgABc@N}@f@s@l@e@b@_AvA{E|JoAvB_ApAKLaCaH[kBW{CEa@GcBQ}AUuAg@}BsCcKiDgN_AwDmBxAkB`BWm@KoAWQMB&key={API_KEY}`

Things to note :

  1. My URL is below 2000 characters
  2. I am using path parameter as per documentation using enc: tag
  3. I have tried replacing \\ with \\\\ as mentioned here

but none of them worked out.is there anything here which I am missing ?

Upvotes: 0

Views: 2014

Answers (3)

Anand Kumbar
Anand Kumbar

Reputation: 11

user encodeURIComponent function which is provided from javascript library itself

path =encodeURIComponent("enc:i}cyHdpc@@?L?@bBAZERwHhNw@zBONULXbC}FjAwBh@eGbB[LGJW]gAmB_@w@_@w@_HnLgDrFqAhBSTQDMn@QfAcApF?^B\Rl@z@xAL@IR]RqA\\YF]@c@NcALWPWZeBbBuFdE}D~CuBlAgA~@c@\\OCy@b@eBb@_DpAuDjBw@n@]v@c@tBe@fBWj@k@d@mExByB|@qBpAYFgABc@N}@f@s@l@e@b@_AvA{E|JoAvB_ApAKLaCaH[kBW{CEa@GcBQ}AUuAg@}BsCcKiDgN_AwDmBxAkBBWm@KoAWQMB")

your_url = https://maps.googleapis.com/maps/api/staticmap?size=600x400&path=${path}&key={API_KEY}

Upvotes: 1

Nicolás Delgado
Nicolás Delgado

Reputation: 41

The problem with this is that the browser does not recognize the ('\\') double backslash. I recommend to replace it by its encoded representation for URLs, i.e. replace every double back slash ('\\') by '%5C'.

DOES NOT CHANGE THE POLYLINE AS THE 'CORRECT' ANSWER SAYS.

In python:

# this is the same url in the question
your_url = "https://maps.googleapis.com/maps/api/staticmap?size=600x400&path=enc:i}cyHdpc@@?L?@bBAZERwHhNw@zBONULXbC}FjAwBh@eGbB[LGJW]gAmB_@w@_@w@_HnLgDrFqAhBSTQDMn@QfAcApF?^B\\Rl@z@xAL`@IR]RqA\\YF]@c@NcALWPWZeBbBuFdE}D~CuBlAgA~@c@\\OCy@b@eBb@_DpAuDjBw@n@]v@c@tBe@fBWj@k@d@mExByB|@qBpAYFgABc@N}@f@s@l@e@b@_AvA{E|JoAvB_ApAKLaCaH[kBW{CEa@GcBQ}AUuAg@}BsCcKiDgN_AwDmBxAkB`BWm@KoAWQMB&key={API_KEY}"

valid_url = your_url.replace("\\", "%5C")

The resulting image for this is: https://i.sstatic.net/mq5Bk.png


This is the resulting image provided in the "correct" answer: https://i.sstatic.net/7c4Tj.png

Upvotes: 1

Nagarjuna Yelisetty
Nagarjuna Yelisetty

Reputation: 539

Google Maps Polyline Decoder

If you carefully check Google Maps Polyline Utility it is appending @ at the end of the encoded polyline entered.

by appending @ at the end of the Encoded polyline path I was able to get the Google Static Image with path drawn on it.

Valid Link:

https://maps.googleapis.com/maps/api/staticmap?size=600x400&path=enc%3Ai}cyHdpc@@?L?@bBAZERwHhNw@zBONULXbC}FjAwBh@eGbB[LGJW]gAmB_@w@_@w@_HnLgDrFqAhBSTQDMn@QfAcApF?^B\\\\Rl@z@xAL`@IR]RqA\\\\YF]@c@NcALWPWZeBbBuFdE}D~CuBlAgA~@c@\\\\OCy@b@eBb@_DpAuDjBw@n@]v@c@tBe@fBWj@k@d@mExByB|@qBpAYFgABc@N}@f@s@l@e@b@_AvA{E|JoAvB_ApAKLaCaH[kBW{CEa@GcBQ}AUuAg@}BsCcKiDgN_AwDmBxAkB`BWm@KoAWQMB@

Upvotes: 1

Related Questions