I'm working in WordPress and want to display embedded Google Maps iframes
. I have added a custom metabox in the backend to hold a text string.
I create the map link using Google Maps, and then save the entire embeddable iframe code. This adds another step to the work flow. I have to manually go to Google Maps, find the address, and save the iframe
code.
I'd prefer to just save the address and have my PHP
convert it to an iframe
. Is there a way in the Google Maps API to get an iframe
just by sending the address and possibly the place name?
Google allows for a URL call that uses an address directly and works in an iframe. You just need to tell Google (as coding addicted pointed out) in the call that the output is embedded.
You make a call to:
https://www.google.com/maps
And you give two GET parameters:
q=[ADDRESS] output=embed
The iframe call would look like this in HTML:
<iframe src="https://www.google.com/maps?q=[ADDRESS]&output=embed"></iframe>
Example:
<iframe src="https://www.google.com/maps?q=Randall Miller %26 Associates 300 E Broadway, Logansport, IN 46947&output=embed"></iframe>
So using PHP, which was part of my original question, I'd put:
<iframe src="https://www.google.com/maps?q=<?php echo $name . ' ' . $address; ?>&output=embed"></iframe>
This is working as of July, 14, 2016.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With