Google map api's current location is not working in some environments.Is there any other service we can use to get the current Geo-location
Asked
Active
Viewed 2,414 times
1 Answers
0
You can use Html5 for this.
See example below:
JS)
<script type="text/javascript">
function showLocation(position) {
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
alert("Latitude : " + latitude + " Longitude: " + longitude);
}
function errorHandler(err) {
if(err.code == 1) {
alert("Error: Access is denied!");
}else if( err.code == 2) {
alert("Error: Position is unavailable!");
}
}
function getLocation(){
if(navigator.geolocation){
// timeout at 60000 milliseconds (60 seconds)
var options = {timeout:60000};
navigator.geolocation.getCurrentPosition(showLocation,
errorHandler,
options);
}else{
alert("Sorry, browser does not support geolocation!");
}
}
</script>
HTML button to call function
<form>
<input type="button" onclick="getLocation();" value="Get Location"/>
</form>

Deedz
- 127
- 1
- 10