1

I have a leads tracking app with a show page that lists all the relevant data associated with the potential lead. I am retrieving the lead's address in the blade view like this:

<div class="data">
<div>{!! $interest->formatAddress() !!}</div>
</div>

Which would render the address in view like: 800 Occidental Ave S Seattle, WA 98134

I want to convert that visible address to a clickable link that would open up a Google Maps page showing that location on the map.

Now I am familiar with resources such as How to convert an address into a Google Maps Link (NOT MAP) or https://developers.google.com/maps/documentation/urls/guide

But I am not understanding how to take what they are presenting and apply it to my blade address code

{!! $interest->formatAddress() !!}

Google docs talk about https://www.google.com/maps/search/?api=1&parameters but I don't understand how to apply my retrieved address information {!! $interest->formatAddress() !!} and integrate it into the parameters part of that URL.

How do I create a clickable address link when my address information is being generated from a database using {!! $interest->formatAddress() !!}.

1 Answers1

3

Like You said, Google Maps can take simple text like this https://www.google.com/maps/place/ADDRESS_HERE so it is super easy.

{{ 'https://www.google.com/maps/place/' . $interest->formatAddress() }}

Or

<a href="https://www.google.com/maps/place/{{ $interest->formatAddress() }}">
   {{ $interest->formatAddress() }}
</a>

Also working with URLs it is good idea to escape special chars with urlencode.

{{ url_encode($interest->formatAddress()) }}

Is has very little to do with Blade itself so I'm not sure where You have problem. It is simple PHP and HTML.

chojnicki
  • 3,148
  • 1
  • 18
  • 32
  • Thanks, this does make it function properly. I appreciate it. Where I was having problems was that from my reading of Google documentation I understood it to be saying I needed to include ?api=1 after the last forward slash right before the inclusion of my parameters. I had been trying -- https://www.google.com/maps/search/?api=1{{ $interest->formatAddress() }}" -- and clearly that was not working. I was under the impression that that ?api=1 part was also required so all my different attempts and modification had that part included. So thanks a lot for your help, it is truly appreciated. – pandorabacchus May 06 '20 at 23:35
  • 1
    Maybe api is required - I did not read documentation. But in this case this also has nothing to do with Blade, it is just way to add parameters in HTTP URL. GET parameters are started by "?" character separated by "&" character so like this: "http://example.com?name=value&name2=value2&name3=value3 etc. But in google maps address is not added as parameter but as path, so /xxxx/yyyyy/zzzz. Based on this it should be simply {{ 'https://www.google.com/maps/place/' . $interest->formatAddress() . '?api=1' }} and that's it. Based on your code it cannot work because You set parameter api to "1ADDRESS" – chojnicki May 07 '20 at 00:04