+ 1
I am not able to make Geolocation API work in HTML5. Will any one please help me to make it work.
please help and give answer to the question
1 ответ
+ 4
Where put you your code?
And have you study JavaScript? The reference of the getCurrentPosition?
https://developer.mozilla.org/en-US/docs/Web/API/Geolocation/getCurrentPosition
To see it working, you can put this code in the JS tab of a web project on sololearn code playground ( and as a classic JS script embeded or linked else ), and next adapt it for your goals:
function pos_success(pos) {
var txt = 'Your current position is:';
txt += '\nLatitude : '+pos.coords.latitude;
txt += '\nLongitude: '+pos.coords.longitude;
txt += '\nMore or less '+pos.coords.accuracy+' meters.';
alert('Geolocation success:\n'+txt);
}
function pos_error(err) {
alert('Geolocation error!\n\n'+err.message);
}
navigator.geolocation.getCurrentPosition(pos_success,pos_error);