1

Information about Google Maps URL syntax is given here How do I link to Google Maps with a particular longitude and latitude? to create a direct link based on Latitude and Longitude. The URL must contain both / and @ symbols.

My Laravel Blade code
<a href="https://www.google.com/maps/search/?api=1&query={{ $country->lat }},{{ $country->long }}/@{{ $country->lat }},{{ $country->long }},5z" target="_blank">

My Desired Output
https://www.google.com/maps/search/33.93911000,67.70995300/@33.93911000,67.70995300,5z

I have 3 problems, but I suspect that they are related.

  • The / is making the URL, but gets updated and encoded as %2F
  • The @ is acting strangely, but @@ will display a single @
  • The blade variable is printing on screen and failing to be interpreted.

My Actual Output
https://www.google.com/maps/search/?api=1&query=33.93911000,67.70995300/@{{ $country->lat}},67.70995300,5z

How do I display these two symbols as-is and display the interpreted variable?

wruckie
  • 1,717
  • 1
  • 23
  • 34
  • `@` is used in `.blade.php` files to signify a template directive, so `@{{ }}` seems to be behaving weirdly. Try `{{ "@{$country->long}" }}` (have the `@` sign _inside_ the `{{ }}`, and combine it with string interpolation). Let me know if that works! – Tim Lewis Jul 05 '22 at 18:49
  • that fixed the @ and variable problem, but it is still not right. Google is adding another whole @ end section again - seems as if the `/` is still causing trouble `https://www.google.com/maps/search/33.93911000,67.70995300%2F@33.93911000,67.70995300,17z/@42.462238,-88.4108341,15z` Google is appending the query with the coordinates of a map view that I previously had on screen. – wruckie Jul 05 '22 at 19:07
  • 1
    It works for me: https://i.stack.imgur.com/KEr3W.png; [generates the URL: `https://www.google.com/maps/search/33.93911000,67.70995300/@33.93911000,67.70995300,5z`](https://i.stack.imgur.com/mhdzM.png), which [opens the correct view](https://i.stack.imgur.com/etOXg.png) (Those are all screenshots of your code working on my local Laravel sandbox) – Tim Lewis Jul 05 '22 at 19:13
  • Sorry, missed that edit. Did you try this code in an incognito browser? If Google is opening it properly, but then modifying it, it may due to some kind of caching that Google Maps does, which is outside the scope of your code. – Tim Lewis Jul 05 '22 at 19:22
  • the link looks like it is being created properly https://imgur.com/rpJqlpF but google maps is treating it strangely https://imgur.com/MjEDf8o – wruckie Jul 05 '22 at 19:29

0 Answers0