Friday, 22 April 2016

Google Map Api Get Latitude and Longitude from Address in JavaScript

Introduction:

Here I will explain how to get latitude and longitude from address Google map api using JavaScript in website.

Description:

By giving latitude and longitude we can get exact location on google map from your website. You can get current latitude and longitude from the user and u can show thier locaion on your website using google api with javascript.

To implement places or address autocomplete textbox using Google maps Google API we need to write the code like as shown below


<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Google Places Autocomplete textbox using google maps api</title>
</head>
<body>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&signed_in=true&libraries=places"></script>
<script type="text/javascript">
google.maps.event.addDomListener(window, 'load', initialize);
function initialize() {
var autocomplete = newgoogle.maps.places.Autocomplete(document.getElementById('txtAutocomplete'));
google.maps.event.addListener(autocomplete, 'place_changed'function () {
// Get the place details from the autocomplete object.
var place = autocomplete.getPlace();
var location = "<b>Address</b>: " + place.formatted_address + "<br/>";
location += "<b>Latitude</b>: " + place.geometry.location.A + "<br/>";
location += "<b>Longitude</b>: " + place.geometry.location.F;
document.getElementById('lblResult').innerHTML = location
});
}
</script>
<span>Location:</span>
<input type="text" id="txtAutocomplete" style="width: 300px" placeholder="Enter your address" /><br/><br />
<label id="lblResult" />
</body>
</html>

1 comment:

  1. Link exchange is nothing else except it is only placing the other person's weblog link on your page at suitable place and other person will also do same in support of you.

    ReplyDelete