Current location ,Web application,ASP.NET,C#

Posted by Raja_89 under ASP.NET on 8/2/2013 | Points: 10 | Views : 1018 | Status : [Member] | Replies : 1
HI
Is it possible to show the current location in terms of latitudes and longtitudes in asp.net C#
[If a person visits that page the corresponding latitude and longtitiude should be displayed ]


Regards




Responses

Posted by: Sheonarayan on: 8/2/2013 [Administrator] HonoraryPlatinum | Points: 25

Up
0
Down
I am not sure about ASP.NET unless user is entering his/her location explicitly and you are passing that value to the Yahoo or Google APIs, however its possible in HTML5.

Below is the code snippet, fire the GetMyLocation() function on click of the button and it will give you an alert with Logitude and Latitude of the user. You can get these values in the server side by sending asynchronus request with these values as querystring to the server using jQuery.

<script type="text/javascript">


// GET LOCATION
function GetMyLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(LocationCallback, FailureCallback);
} else {
alert("Sorry, your browser doesn't support Geolocation");
}
}

function LocationCallback(position) {
alert('Latitude: ' + position.coords.latitude + '\n' + 'Longitude: ' + position.coords.longitude + '\n' + 'Accuracy: ' + position.coords.accuracy);
}

// FAILURE
function FailureCallback(error) {
alert('Sorry, an error occured - ' + error);
}

</script>


Hope this helps.

Thanks

Regards,
Sheo Narayan
http://www.dotnetfunda.com

Raja_89, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response