I'm trying to learn how to use HTML5 geolocation and am having trouble getting the following script to run properly:
<script src="js/jquery-1.4.2.min.js"></script>
<script>
jQuery(window).ready(function(){
jQuery("#btnInit").click(initiate_geolocation);
});
function initiate_geolocation() {
navigator.geolocation.getCurrentPosition(handle_geolocation_query);
}
function handle_geolocation_query(position){
alert('Lat: ' + position.coords.latitude + ' ' +
'Lon: ' + position.coords.longitude);
}
</script>
My HTML contains a button that references the #btnInit jQuery function; however, the script does not display any alert popup boxes. Moreover, it seems that the script is pausing prior to the line: jQuery(window).ready(function(){
What are my next steps for getting HTML5 geolocation working?
Your code works perfectly for me, see this fiddle. Is your browser supporting geolocation?
Depending on your browser, you should see somewhere a notice to allow the browser to get your location. You must allow this, to get your code working.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With