Find Geo Location By Longitude and Latitude using Google Map API

Latitude and Longitude are unit for geographical cordinates and you frequently need to pick geolocation for user profiles, outlets etc. Here we described the use of Google Geo Location API.

To create map and map events first you need to register on google and take a geo location API Key.

To get the Key follow the Following link:

In Google developer console create a new project and Enable Google Maps JavaScript API and Google Maps Geocoding API. You will get the Google Map API Key there.

Now in your page write HTML:

         #mapCanvas {
            width: 690px;
            height: 370px;            
         <h2>Find Geo Location By Longitude and Latitude</h2>
                  <textarea id="address" rows="3" cols="40"></textarea></td>               
               <td valign="top">
                  <input type="button" value="Get Map" onClick="codeAddress()">
         <table width="100%"  border="0" align="left" cellpadding="2" cellspacing="4">
               <td width="6%" class="label" >Latitude:</td>
               <td width="14%">
                  <input name="lati" type="text" style="width:150px;" class="txtFieldnol" id="lati" size="15" value="" />
               <td width="8%" class="label">Longitude:</td>
               <td width="14%">
                  <input name="longi" type="text" style="width:150px;" class="txtFieldnol" id="longi" size="15" value=""   />
                     <input type="button" name="get" value="Change"  class="Thbutton gray medium" onClick="post_value();" />                  
         <div id="mapCanvas"></div>
         <div id="infoPanel">
            <b>Marker status:</b>
            <div id="markerStatus"><i>Click and drag the marker.</i></div>
            <b>Current position:</b>
            <div id="info"></div>
      <script type="text/javascript" src=""></script>
      <script type="text/javascript" src="mapinit.js"></script>
Now create a Javascript File mapinit.js and put the following:
// Initialise Variables for Google Map API
var geocoder;
var map;
var marker;
var geocoder = new google.maps.Geocoder();
var startLong = 26.8394676242502;
var startLat = 80.9542695781251;
// Function to Update Address of Geo Location
function geocodePosition(pos) {
      latLng: pos
   }, function(responses) {
      if (responses && responses.length > 0) {
      } else {
         updateMarkerAddress('Cannot determine address at this location.');
// Function to Update Marker's Status
function updateMarkerStatus(str) {
   document.getElementById('markerStatus').innerHTML = str;
// Function to Update Marker Position
function updateMarkerPosition(latLng) {
   document.getElementById('info').innerHTML = [,
   ].join(', ');
   document.getElementById('lati').value =;
   document.getElementById('longi').value = latLng.lng();

// Function to Update Address in Textbox 
function updateMarkerAddress(str) {
   document.getElementById('address').innerHTML = str;
// Function to Initilise Google Map
function initialize() {
   var latLng = new google.maps.LatLng(startLong, startLat);
   map = new google.maps.Map(document.getElementById('mapCanvas'), {
      zoom: 8,
      center: latLng,
      mapTypeId: google.maps.MapTypeId.ROADMAP
   marker = new google.maps.Marker({
      position: latLng,
      title: 'Your Position',
      map: map,
      draggable: true

   // Update current position info.

   // Add dragging event listeners.
   google.maps.event.addListener(marker, 'dragstart', function() {

   google.maps.event.addListener(marker, 'drag', function() {

   google.maps.event.addListener(marker, 'dragend', function() {
      updateMarkerStatus('Drag ended');
// Function to Convert Address to Geo Position
function codeAddress() {
   geocoder = new google.maps.Geocoder();
   var address = document.getElementById("address").value;
   geocoder.geocode({'address': address}, function(results, status) {
      if (status == google.maps.GeocoderStatus.OK) {

         document.getElementById("lati").value = results[0];
         document.getElementById("longi").value = results[0].geometry.location.lng();

         marker.position = results[0].geometry.location; = map;
         map.draggable = true;
      } else {
         alert("Geocode was not successful for the following reason: " + status);
// Function to Update Marker Using Textbox Longitude and Latitude
function post_value()
   var latLngPos = new google.maps.LatLng(document.getElementById("lati").value, document.getElementById("longi").value);
   marker.position = latLngPos; = map;
   map.draggable = true;
// Onload handler to fire off the app.
google.maps.event.addDomListener(window, 'load', initialize);
Your final output will be work like this: