I am not able to make Geolocation API work in HTML5. Will any one please help me to make it work. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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

13th May 2017, 8:41 AM
Harsh
Harsh - avatar
1 Answer
+ 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);
13th May 2017, 9:59 AM
visph
visph - avatar