Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert Place Name & Address to Google Maps URL And iFrame

Tags:

Background

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.

Currently

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.

Goal

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?

like image 810
Andy Mercer Avatar asked Jan 15 '14 14:01

Andy Mercer


1 Answers

Updated As of Jan. 2016

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.

like image 126
Andy Mercer Avatar answered Sep 20 '22 19:09

Andy Mercer