Create Custom Google Maps using Google Map API

Introduction

 
In this blog, you can see the code for:
  1. Get the current location.
  2. Get location using longitude and latitude
For this map you have to add these js.
  1. <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>    
  2.    <script type="text/javascript" src="http://google-maps-utility-library-v3.googlecode.com/svn/trunk/infobox/src/infobox.js"></script>   
Get current location
  1. if (navigator.geolocation) {    
  2.         navigator.geolocation.getCurrentPosition(success);    
  3.     }     
  4.     function success(position) {    
  5.         var address;    
  6.         var txtLongitude = position.coords.longitude;    
  7.         var txtLatitude = position.coords.latitude;    
  8.         var geocoder = new google.maps.Geocoder();    
  9.         var latlng = new google.maps.LatLng(txtLatitude, txtLongitude);    
  10.             
  11.         geocoder.geocode({ 'latLng': latlng }, function (results, status) {    
  12.             if (status == google.maps.GeocoderStatus.OK) {    
  13.                 if (results[1]) {    
  14.                     alert(results[1].formatted_address + "\r\nLatitude: " + txtLatitude + "\r\nLongitude: " + txtLongitude);    
  15.                 }    
  16.             }    
  17.         });    
  18.     }    
Get location using longitude and latitude
  1. function CreateGoogleMap(latitude, longitude, address) {    
  2.         var loc, map, marker;    
  3.         loc = new google.maps.LatLng(latitude, longitude);    
  4.         map = new google.maps.Map(document.getElementById("Google_Map"), {    
  5.             zoom: 12,    
  6.             center: loc,    
  7.             mapTypeId: google.maps.MapTypeId.ROADMAP    
  8.         });    
  9.   
  10.         marker = new google.maps.Marker({    
  11.             map: map,    
  12.             icon: pointer.png",    
  13.             position: loc,    
  14.             visible: true    
  15.         });    
  16.   
  17.         google.maps.event.trigger(map, "resize");    
  18.     }  
For complete code, you can download the attachment.
 
Thanks
Next Recommended Reading Map - Key Value Pair In JavaScript