user2649441
user2649441

Reputation: 13

How to convert an address into a Google Maps Link

I have the following code that is pulling an address in from a database.

 <td class="center"><?php echo ($customer->address!='')?$customer->address:'NA';?></td>

And displaying the address on an admin area.

i would like the address to be linked to google maps using

<a href="maps.google.com/?p= {then the addy} "> {the addy} </a>

But when i add the link to the code the code breaks.

The most recent attempt was

<td class="center"><a href="http://map.google.com/?p=<?php echo ($customer->address!='')?$customer->address:'NA';?>"><?php echo ($customer->address!='')?$customer->address:'NA';?></a></td>

Upvotes: 1

Views: 7255

Answers (2)

Keith A
Keith A

Reputation: 801

your code is fine and should work just change your google address to https://maps.google.com/maps?q=

Upvotes: 6

putvande
putvande

Reputation: 15213

All you have to do for a valid Google Maps URL is just to go to http://maps.google.com, type in the address you want to have and click on the 'link button'. You can strip down to a shorter version which still works. So for example: 1 5th Avenue, Manhattan, New York would be something like https://maps.google.co.uk/maps?q=1+5th+Avenue,Manhattan,New+York,United+States. So just add ',' between the parts of the address and a '+' for each space.

Upvotes: 1

Related Questions