Tell me more ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

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.

Please could I get some critical assesment of the following and if 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 googlemaps once the lat/lng's 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();
}

Thanks to anyone that would like to throw their tupence in! :)

share|improve this question

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.