0

I'm getting an overview polyline from google directions between two points then pass it as "enc:" parameter to static maps.

Once the image is rendered the polyline follows the actual shape of the road but it's displaced hundred of meters or maybe one kilometer.

Markers are set to the same coords passed to directions API but markers are displayed correctly.

I also tried to set the static maps geodesic parameter to "true" but had the same problem.

See:

https://maps.googleapis.com/maps/api/staticmap?markers=color:green%7Clabel:A%7C21.0453333,-86.78226990000002&markers=color:red%7Clabel:B%7C21.038007,-86.869206&size=640x320&path=weight:6%7Ccolor:blue%7Cenc:%7Dkm_CpytpOcJTqBCyDOiAECDCF?H@FjCL%7CBFjEIL[lEQpBCv@?xAHdBN%7C@LBZBf@nBt@%7CDrBzBnAbBz@vAd@nBX~AFpACxACAJtAd@j@%5Ch@h@%5Cr@R%7C@Dv@EdAMf@s@BoCxFaErIoC%7CFOZk@t@]t@]dA[BGv@Ap@HjEHERrJHzCHz@TnA%5CfAn@rAtHjPpAtCv@xBjBnFZp@Vh@b@n@hBnBfB~B%7CLvQ~AxB@d@z@l@v@b@vAd@nCz@Ct@zBr@tAv@t@r@j@z@h@vAPv@F@DhACAKA%7B@nDQf@cJ~_@wKle@kEReDvNiLvf@[pAm@zAu@~Aa@lAIb@QxAQzBMhAm@lCoAnFcAjEGr@C%5EBdAB%5EN~@Vt@Zp@%5Ef@%7C@z@hEpD%7C@z@d@n@%5Ev@Pt@LlAAx@GlA@JC%5ECZKrBUvCUpAa@lAcAhBg@ASXOJEFsAdCe@z@aCpEoBfD%7BCjFw@zAiEnIyFtK%7BOzY%7DFzKGVoCdFYAIb@@j@FT%5Eh@zD~BzDCXD%5CFRCVUh@aAxAwCvBgDJQbC%7DEd@UVIh@IX@%5EOHBZEbAYPSLWn@kA&key=AIzaSyDdFa0XLRwG7iR24xU8849VSpV-iBWY6U0

or

https://maps.googleapis.com/maps/api/staticmap?markers=color:green%7Clabel:A%7C21.038007,-86.869206&markers=color:red%7Clabel:B%7C21.0880741,-86.77087180000001&size=640x320&path=weight:6%7Ccolor:blue%7Cenc:o~k_CpseqOh@iA@@IWg@@YOWCODMNaBtCYJc@F%7BANe@Ag@E%7BBwAyCoBg@O_@o@EMCk@FWRk@nDyG~Sm@r@mABcDbBaDzKsSFY@o@z@aBp@uA%5EwALaAXeFHeAFGFw@AsBIw@Ss@[s@iA%7BAqE%7DDk@c@a@g@i@%7B@Qk@YuAGaA@u@JeAjCcL%7C@sD~@_Cb@aAJYPo@PaAPcCP%7DAP%7B@tGaYfJ%7B@b@cBz@mCxBkGZkAnAiJPeAlAuFxCqMbBoGp@%7DCh@iCd@%7BAd@_AlAkBj@cANg@Hi@d@iDr@_GHuBAw@I%7D@U_Ag@oAu@cA%7D@y@yAq@uA[cJq@oAQkAa@wAkAkTm%5C_CuDcAcBm@iAcB%7DDkG_NsBmEc@cA[kASgAIy@IcCUqIQuJDeBJy@Ny@V%7B@v@iBfA_ChDiHrFoLBaDd@gANy@AaAS%7B@OYa@g@qA%7BAc@[w@Yu@KcABaBNaAB_CMkBYiA_@mDiBmDoBwBeB_Ag@q@_@%7B@OuASmB?iIZ_JZ_GNoC?iHWkPo@%7DI]%7DBQcCG_CCuCa@%7D@QyJgBcASq@Us@[c@e@gBmBwAcBy@m@w@a@sAc@qBa@mB[BI%7B@?y@HoAPsBXcJnAwNtBk@F@?mAWuA_@uDcAcBi@eA_@s@]uDuBcIqEm@c@i@Uw@QsDe@eHyAsLeCcEeAqDk@cO_FoL%7DCaD%7D@oAm@gBm@iAWsAk@?OCe@Li@Pe@d@w@h@y@NU&key=AIzaSyDdFa0XLRwG7iR24xU8849VSpV-iBWY6U0

I'm sending the final Static Maps URL through an email.

R.Minor
  • 24
  • 4
  • What does the original poly line from the directions service look like (or what is the request you made to obtain it)? – geocodezip Mar 21 '17 at 23:29
  • @geocodezip https://maps.googleapis.com/maps/api/directions/json?origin=21.038007,-86.869206&destination=21.0880741,-86.77087180000001&key=AIzaSyDdFa0XLRwG7iR24xU8849VSpV-iBWY6U0 – R.Minor Mar 22 '17 at 13:45
  • @geocodezip for both cases: case 1: https://maps.googleapis.com/maps/api/directions/json?origin=21.0453333,-86.78226990000002&destination=21.038007,-86.869206&key=AIzaSyDdFa0XLRwG7iR24xU8849VSpV-iBWY6U0 case 2: https://maps.googleapis.com/maps/api/directions/json?origin=21.038007,-86.869206&destination=21.0880741,-86.77087180000001&key=AIzaSyDdFa0XLRwG7iR24xU8849VSpV-iBWY6U0 With that you get a json, and I take the "overview_polyline" -> "points" string – R.Minor Mar 22 '17 at 13:52

1 Answers1

0

I just figured it out.

The problem:

Obtained "overview_polyline" from Google Directions JSON response contained a lot of special characters that were bad escaped once the URL pass through the mail server.

I concatenate the static maps url with the "overview_path" in PHP, so to make sure all characters were well escaped I used the rawurlencode function (https://stackoverflow.com/a/1734255/7441808):

$revert = array('%21'=>'!', '%2A'=>'*', '%27'=>"'", '%28'=>'(', '%29'=>')');
$wellEscapedString = strtr( rawurlencode($original_string), $revert );

Now the line matches perfect to the road.

Community
  • 1
  • 1
R.Minor
  • 24
  • 4