Search code examples
phpgoogle-mapsgoogle-maps-embed

Google Map embedded populated by address string


So i have collected addresses in my database in the following format:

address line 1 | address line 2 | post code

How can i pull this in through php to generate an embedded google maps?

Someone like this is what im looking for:

<?php    
    $address = $address_line_1 . $address_line_2 . $postcode
?>


<iframe src="http://www.google.com/maps/embed?<?= $address ?>"></iframe>

Solution

  • See the documentation for the "place mode":

    The following URL parameter is required:

    q defines the place to highlight on the map. It accepts a location as either a place name, address, or place ID. The string should be URL-escaped, so an address such as "City Hall, New York, NY" should be converted to City+Hall,New+York,NY. (The Google Maps Embed API supports both + and %20 when escaping spaces.)

    <iframe width="600" height="450" frameborder="0" style="border:0" src="
      https://www.google.com/maps/embed/v1/place
       ?key=YOUR_API_KEY
       &q=Eiffel+Tower,Paris+France
    "></iframe>
    

    example