egeloen / IvoryGoogleMapBundle

Google Map API v3 integration for your Symfony2 project.
https://github.com/egeloen/ivory-google-map
MIT License
217 stars 152 forks source link

Rendering Encoded Polylines seems to not be working due to character escaping #183

Closed markbijl closed 7 years ago

markbijl commented 7 years ago

Hi @egeloen,

Hope you are well? I've been using your bundle(s) more and more, again, thanks for your work on these. However, I was trying to display a route using an encoded polyline when I ran into the following. I used the Direction service to plot a route and retrieve an encoded polyline from it. When rendering the encoded polyline, however, it seems that some characters are being escaped which results in an erroneous route (though some very interesting 'art' appears!!! 😄 )

Encoded polyline as returned by the Google API: okmwF~yubMmyKjzk@yaPtqYycGzso@{jDrlxA_bItwImUdjN}~NnqZalAly\z~Brbu@j~Hh~cA{aBv~~@piEt~h@{vOnn_A`jB`xe@scAx_e@pkKnud@ptJpgY}oGdfPstEbzOreHzoYykA~~VokFfag@wsQdcn@m{BbofA}jGhjr@wz@z~aAgHjpy@vmAtdeB~aDtpp@pmGd_\izDx_My}QbbV}h@zwu@ocGrgjAmpNx_u@{l@~t|@zxGp`c@c\x{t@keOxmuAoeYrakAo{F`l{AgwC~n}B{kEhn`@wkNbyWepAhyz@_cAh|x@tsCxznBaqAdlp@xlB|hf@|sUfvo@xgF`hy@ke@n`cB`{QxhnB~bSfwi@xrA`hfCifEtiw@ty@dmQwBjpz@wdIx_xAm|A~s|@g`UneN{}E|`GivD|{b@ggArsd@gtB|d\gtChirBmt@~ohBwA`v~CbmGjxiA~`Dj~e@tdHjyIleFdy\ztHzvo@eMn_b@aFrbxBaHfmfB`f]~s]~}Tb}Vno@zu]`sDhwQ`rOjgXh|RhwObfUvjo@`kKjqc@h{@|ou@uFfw{E|`Ariw@dhP|ao@tjHp~kBe~EzarAwviAbh_E{iGb}}@p{Bl|y@{WzzlAthJzj}@riAlhiAseKjmqAm{Azml@ydNneu@}t@blgAtyI~~pB|wIjbuCcwGfjcAmfQpfI{sH`xPktJ~}X{zGnv^g~h@tknA{oQ`hc@mqEdrf@qdFd_gCj_Xjq`D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Vno@zu]`sDhwQ`rOjgXh|RhwObfUvjo@`kKjqc@h{@|ou@uFfw{E|`Ariw@dhP|ao@tjHp~kBe~EzarAwviAbh_E{iGb}}@p{Bl|y@{WzzlAthJzj}@riAlhiAseKjmqAm{Azml@ydNneu@}t@blgAtyI~~pB|wIjbuCcwGfjcAmfQpfI{sH`xPktJ~}X{zGnv^g~h@tknA{oQ`hc@mqEdrf@qdFd_gCj_Xjq`DnBpo_BedF|b`@vpB~f_@zcJfkp@r_O|bg@egFd}VfdCxis@pfXfb~@tnUjpgBraInlaApt^nsi@~lLrhXjhL~aItySmgEjkJx_MvjHt_EghB`uSvyB|a^`tAd{OqhF~uLu{Armh@t_NzdZx`Dt|T{{Fjn\\\\mmTjqdAptPtgo@ciAzdpCe_Ahgm@ib_AvuyAkvEp{f@zt@jdy@ftNbf}@fpMdsXxzKxzc@|vPruYhaN~|[}Cli[ziNz`e@_|H`c\\\\t`Efyq@ffGfa[eqM`nSg`PdxTunZh`q@adSftm@`zTpqq@hgYbe[pzQviK|tEruUv{WteQvob@trFbl`@by_@xmLfsRdzSzuQt_f@vlaAnz[~b]xxCxkOzdDttYddN|pp@aMtlo@pa@~`RxiUvjDp~@dcK|rJpcTgThfa@oSrtg@foQ|}`@vq]hfg@~jVjtLtuc@vei@bhYlw_@htJra\\\\b}Wl|w@tbYhwa@rca@`kg@of@`nZtsKvu^rgf@kwC`~HoeF

An excerpt from my code:

$direction = new DirectionService(new Client(), new GuzzleMessageFactory());
$response  = $direction->route(new DirectionRequest(
  new AddressLocation(...),
  new AddressLocation(...)
));

  ...

foreach ($response->getRoutes() as $route) {
  ...
  $this->getOverlayManager()->addEncodedPolyline($route->getOverviewPolyline());
  ...
}
egeloen commented 7 years ago

First, thanks for your bug report! It seems related to the way the json builder build the json... Can you try to hardcode the json encode options in the JsonBuilder constructor in order to see if it fixes your issue. If yes, I can look to fix it in a nicer way...

Basically, I want you to update the JsonBuilder cosntructor with:

public function __construct()
{
    $this->accessor = new PropertyAccessor();
    $this->reset();
    $this->setJsonEncodeOptions(JSON_UNESCAPED_SLASHES);
}
egeloen commented 7 years ago

ping @markbijl :)

markbijl commented 7 years ago

Hi Erik, thanks for your feedback and sorry for the late reply. I'm currently on a business trip, but will try this a.s.a.p.! Thanks!

egeloen commented 7 years ago

Ok no problem :) Since I hav also a buggy branch related to encoded polylines, I will probably fix it meanwhile.

markbijl commented 7 years ago

Hi @egeloen,

I still owed you a response on this matter, my apologies for the delayed response. Indeed, the proposed solution did fix the problem as you predicted. In the mean time, I also updated my libraries, and I can confirm that your latest updates also corrected the issue, so

QA: ✔️

Thanks!