aspdotnet-suresh offers articles and tutorials,csharp dot net, articles and tutorials,VB.NET Articles,Gridview articles,code examples of 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

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.


To get current location latitude and longitude using Google Maps 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 = "<b>Latitude</b>: " + geolocation.A + "<br/>";
location += "<b>Longitude</b>: " + 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" />


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


RAHUL 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

AV said...

its working only on localhost.when i deploy this code on server Lat and long are unable to find.

Give your Valuable Comments

Note: Only a member of this blog may post a comment.

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