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
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>