I've written this code that I've been using for a while now to check for browser geolocation services for Google Maps applications. I have to say that I am not very happy with it as I've had to hack it quite a bit to work in IE9.
Could I please get some critical assessment of the following and possible suggestions for an elegant solution? I need to stress that I do not want to use Modernizr or Gears. However, if there are good arguments, I'm willing to listen.
Notes: All the vars and functions in this script do pretty much as the function or var describes. All variables are declared as jQuery objects. start()
launches Google Maps once the latitudes/longitudes are set.
function checkGeolocate()
{
return 'geolocation' in navigator;
}
if (checkGeolocate())
{
// Note that the if condition does not start until the end of the
// entire geolocation procedure.
if(navigator.geolocation.getCurrentPosition(function(position)
{
userLat.val(position.coords.latitude);
userLng.val(position.coords.longitude);
userDist.val(25);
start();
mapControls.fadeIn(200);
mapOverlay.fadeOut(100);
},
function(error)
{
console.log(error);
displayPostcodeSelect();
},
{
timeout : 5000,
maximumAge : 90000,
enableHighAccuracy : true
}))
{
// Do nothing as script has started
// This if clause is to force IE9 to error out
// instead of hanging when geolocation throws a PERMISSION_DENIED error.
}
else {
displayPostcodeSelect();
}
}
else
{
console.log('no geo support');
displayPostcodeSelect();
}