How to retrieve latitude and longitude of a draggable pin via Google Maps API

Latitude and longitude are spherical coordinates used to locate a point on the earth. Many maps do not need to take the curvature of the earth into account.

Latitude:

Latitude is the Y coordinate and characterizes north-south worldwide position estimated from the equator. Lines of steady latitude are called matches since they characterize a progression of rings corresponding to the equator. Equals run east-west, yet characterize north-south situation on the globe. Equals are assigned in degrees from 0° at the Equator to 90° at the shafts. Surfer utilizes the show that equals are positive north of the equator (north latitudes), and negative south of the equator (south latitudes). Assignments, for example, 45° demonstrate a position 45 degrees north of the equator, while – 65° shows a position 65 degrees south of the equator. At any situation on the globe, the distance covered by a level of latitude remains almost steady.

Latitude and Longitude Coordinates
Latitude and Longitude Coordinates

Longitude:

Longitude is the X coordinate and demonstrates east-west situation on the globe. Lines of steady longitude are called meridians. Meridians lie at right points to the equals and are half-circles drawn from the North Pole toward the South Pole. One meridian is assigned as the great meridian. The superb meridian most ordinarily being used in the United States goes through Greenwich, England, in spite of the fact that there are a few other prime meridians being used all through the world. Longitude is estimated 180° east and 180 degrees west from the excellent meridian. In Surfer, longitude is positive (east longitude) of the excellent meridian, and negative west of the great meridian (west longitude). An assignment, for example, – 105° is utilized to show an area 105 degrees west of the excellent meridian. Meridians merge at the poles so the distance covered by one level of longitude diminishes as you move north or south from the equator.

by using this code you can retrieve latitude and longitude form google map

JavaScript Code:

<script type="text/javascript">
  var map; 
function initialize() { 
  var myLatlng = new google.maps.LatLng(40.713956,-74.006653);
  var myOptions = { zoom: 8, center: myLatlng, mapTypeId: google.maps.MapTypeId.ROADMAP } 
  map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); 
  var marker = new google.maps.Marker({ draggable: true, position: myLatlng, map: map, title: "Your location" }); 
  google.maps.event.addListener(marker, 'dragend', function (event) { 
    document.getElementById("latbox").value = this.getPosition().lat(); 
    document.getElementById("lngbox").value = this.getPosition().lng(); 
  }); 
}
</script>

HTML Code:

<div id="map_canvas" style="width: 50%; height: 50%;"</div>
<div id="latlong">
  Latitude: <input id="latbox" name="lat" size="20" type="text" /> 
  Longitude: <input id="lngbox" name="lng" size="20" type="text" />
</div>
<script async defer src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&callback=initMap"
</script>

Leave a Reply

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