geolocation | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson


between which tag geolocation comes. its not working for me the command just displayed on the screen as "navigator.geolocation.getCurrentPosition();

10th May 2017, 9:11 AM
Ajith Kumar.S
Ajith Kumar.S - avatar
2 Answers
+ 5
Where put you your code? And have you study JavaScript? The reference of the getCurrentPosition? Because you don't provide arguments, and at least one is required ( two, is minimal, as the first is a callback function used in case of success, and the second a callback in case of error, like user denied authorization of location ^^ ): 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);
10th May 2017, 9:36 AM
visph - avatar
+ 1
Last time I tried in the SL app it didn't work (i suppose it due to do with missing app permissions). In the browser there should be no problem: just login at from firefox/chrome and run the code. You'll probably get a prompt from the browser requesting you to grant permission to access your location. Same thing happens with camera input and audio input.
10th May 2017, 11:52 AM
seamiki - avatar