Sunday, June 21, 2015

Google Map Api Get current location Latitude and Longitude in JavaScript

Here I will explain how to get latitude and longitude from address Google map api using JavaScript in website or Google maps autocomplete address textbox to get latitude and longitude without map example. By using google.maps.places.Autocomplete class we can implement Google places autocomplete textbox and display selected address latitude and longitude details.

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

<html xmlns="">
<title>Google Maps Api Get Current Location Latitude and Longitude</title>
<script src=""></script>
<script type="text/javascript">
function geolocate() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function (position) {
var geolocation = new google.maps.LatLng(
position.coords.latitude, position.coords.longitude);
var location = "Latitude: " + geolocation.A + "
location += "Longitude: " + geolocation.F;
document.getElementById('lblResult').innerHTML = location
<div style="margin-top:200px; margin-left:200px">
<input type="button" id="btnGet" value="Get Latitude & Longitude" onclick="geolocate()" /><br /><br />
Current Location Latitude & Longitude:<br /><br />
<label id="lblResult" />

No comments:

Post a Comment