Google map by address

Google map provides so many features for developers to show google map in website. Today in this post, I am explaining one of the method to show google map by address. You can choose whatever address you want to display in map.

To show map I have created one function generate_googlemap() to generate iframe. You have to just call function and pass some parameters to function and it will generate iframe according to parameters and display iframe on webpage.b

Google map by address

For iframe following attributes we have used in our function.
1. id – required parameter
2. adress – required parameter
3. width – optional parameter
4. height – optional parameter
5. frameborder – optional parameter
6. scrolling – optional parameter
7. marginheight – optional parameter
8. marginwidth – optional parameter

function generate_googlemap($id, $address, $width="600", $height="500", $zoom_level="14", $frameborder = "0", $scrolling="no", $marginheight="1500", $marginwidth="1500"){

  //remove replace space with plus(+) sign and comma with blank space
  $format_address = str_replace(",", "", str_replace(" ", "+", $address));

  //generate url by passing address and zoom level
  $url = "https://maps.google.com/maps?q=".$format_address."&t=&z=".$zoom_level."&ie=UTF8&iwloc=&output=embed";

  //generate iframe by passing all variables data to attributes
  echo '<iframe id='.$id.' width='.$width.' height='.$height.' frameborder='.$frameborder.' scrolling='.$scrolling.' marginheight='.$marginheight.' marginwidth='.$marginwidth.' src='.$url.'></iframe>';

}

You can call this function by passing id and address to it like this :

generate_googlemap('my_address', 'college road nashik');

It will generate iframe (output) like this :

<iframe id="my_address" scrolling="no" marginheight="1500" marginwidth="1500" src="https://maps.google.com/maps?q=college+road+nashik&t=&z=14&ie=UTF8&iwloc=&output=embed" width="600" height="500" frameborder="0"></iframe>


Conclusion :

As you can see, to generate google map by address whatever you want is not so difficult. we have made one function to generate iframe. In future post we will see some more features provided by google for map or other api. So stay connected with my blog to get useful stuff in simple manner, and i will be more happy to get some feedback from you in comment section, and also share this post if you like if it is useful for others. Thanks.

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.