Aspdotnet-Suresh

aspdotnet-suresh offers C#.net articles and tutorials,csharp dot net,asp.net articles and tutorials,VB.NET Articles,Gridview articles,code examples of asp.net 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

Google Map API Get Current Location Latitude & Longitude using JavaScript

Jun 19, 2015
Introduction:

Here I will explain how to get current location latitude and longitude in Google map using JavaScript or Google maps get current location latitude and longitude using Google API in JavaScript example. By using navigator.geolocation.getCurrentPosition class we can get current location latitude and longitude using Google map.

Description:


To get current location latitude and longitude using Google Maps API we need to write the code like as shown below


<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Google Maps Api Get Current Location Latitude and Longitude</title>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&signed_in=true&libraries=places"></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 = "<b>Latitude</b>: " + geolocation.A + "<br/>";
location += "<b>Longitude</b>: " + geolocation.F;
document.getElementById('lblResult').innerHTML = location
});
}
}
</script>
</head>
<body>
<div style="margin-top:200px; margin-left:200px">
<span>Location:</span>
<input type="button" id="btnGet" value="Get Latitude & Longitude" onclick="geolocate()" /><br /><br />
Current Location Latitude & Longitude:<br /><br />
<label id="lblResult" />
</div>
</body>
</html>

Demo

Google Map Api Get Current Location Latitude and Longitude using JavaScript


If you enjoyed this post, please support the blog below. It's FREE!

Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email

5 comments :

Unknown said...

this API is not working for me...showing undefined error message.

Unknown said...
This comment has been removed by the author.
Unknown said...

I tested how to has in your explaining, but i couldn't get the longitude and latitude. The result was undefined

Anonymous said...

var geolocation = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);

remove this line and get lat long from position direct

Anonymous said...

What need to remove

Give your Valuable Comments

Other Related Posts

© 2015 Aspdotnet-Suresh.com. All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.