Tuesday, 15 September 2015

javascript - how to allow geolocation in web page -



javascript - how to allow geolocation in web page -

i have been trying run code latitude , longitude. ie browser shows message geolocation services not supported, , chrome says 'this page has been blocked tracking location' after set location setting in chrome allow sites track. please help.

<html> <head></head> <body> <input type="button" id="btnsearch" value="search" onclick="dosomething();"/> <script> function dosomething(){ if (navigator.geolocation) { navigator.geolocation.getcurrentposition(handle_geolocation_query); function handle_geolocation_query(position) { alert('lat: ' + position.coords.latitude + ' ' + 'lon: ' + position.coords.latitude); } } else { alert("i'm sorry, geolocation services not supported browser."); } } </script> </body> </html>

change scope of handle_geolocation_query() outer, , should work. works on ie , firefox after changes.

<html> <head></head> <body> <input type="button" id="btnsearch" value="search" onclick="dosomething();"/> <script> function dosomething(){ if (navigator.geolocation) { navigator.geolocation.getcurrentposition(handle_geolocation_query); } else { alert("i'm sorry, geolocation services not supported browser."); } } function handle_geolocation_query(position) { alert('lat: ' + position.coords.latitude + ' ' + 'lon: ' + position.coords.latitude); } </script> </body> </html>

javascript html5 geolocation

No comments:

Post a Comment