Reputation: 1841
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?
Upvotes: 3
Views: 3822
Reputation: 11
html 5 geoloaction is working on ie9 but not in Mozilla higher version and IE lower version so better use location by ip
Upvotes: 1
Reputation: 1
I've had the same issues, my solution was to run geolocation from a wifi point of reference rather than ethernet. All I can suggest is my modem is firewalling any requests back about me and my location through my private network, but then locates my position through my mac address and SSID reference. See the article: How, exactly does HTML5's GeoLocation work?
Upvotes: 0
Reputation: 18979
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.
Upvotes: 1