Google map with marker for your contact page

Published on : June 3, 2014

Author:

Category: PHP


To get Google map you need latitude and longitude of your address. You can easily find latitude and longitude from several sites (i.e. http://www.gps.ie/gps-lat-long-finder.htm). Here I will use google map API 3 to get accurate marker of my address.
First take a div with an id and don’t forget to set height and width. Like-


<div id="contact-map "></div>

Secondly, create a javascript function with following code-


function contact_map() {
   var mapOptions = {
      zoom: 4,
      center: new google.maps.LatLng(your latitude, your  longitude),
      mapTypeId: google.maps.MapTypeId.ROADMAP
   };
   map = new google.maps.Map(document.getElementById('your_div_id'),mapOptions);
}

Now, just call your javascript function with the following code-
google.maps.event.addDomListener(window, ‘load’, contact_map);
So, you contact map is ready. to get map market just add following code into your javascript function(i.e. contact_map)


var marker = new google.maps.Marker({
   position: map.getCenter(),
   map: map,
   title: 'Click to zoom'
});


Leave a Reply

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