Skip to Content
Menu

geoSuccessCallback()

Store geolocation data when successfully detected from the Google Maps API.

JavaScript February 7, 2021

Usage

This function runs automatically, so it is not called manually. Is this incorrect?

Additional Notes

This function triggers geolocationSuccess when finished so the nebula.session.geolocation can be used.

Was this page helpful? Yes No


    A feedback message is required to submit this form.


    Please check that you have entered a valid email address.

    Enter your email address if you would like a response.

    Thank you for your feedback!

    Source File

    Located in /assets/js/modules/location.js on line 201.

    No Hooks

    This function does not have any filters or actions available. Request one?
    JavaScript
    function geoSuccessCallback(position){
        nebula.session.geolocation = {
            error: false,
            coordinates: { //A value in decimal degrees to an precision of 4 decimal places is precise to 11.132 meters at the equator. A value in decimal degrees to 5 decimal places is precise to 1.1132 meter at the equator.
                latitude: position.coords.latitude,
                longitude: position.coords.longitude
            },
            accuracy: {
                meters: position.coords.accuracy,
                miles: (position.coords.accuracy*0.000621371).toFixed(2),
            },
            altitude: { //Above the mean sea level
                meters: position.coords.altitude,
                miles: (position.coords.altitude*0.000621371).toFixed(2),
                accuracy: position.coords.altitudeAccuracy,
            },
            speed: {
                mps: position.coords.speed,
                kph: (position.coords.speed*3.6).toFixed(2),
                mph: (position.coords.speed*2.23694).toFixed(2),
            },
            heading: position.coords.heading, //Degrees clockwise from North
            address: false
        };
    
        if ( nebula.session.geolocation.accuracy.meters < 50 ){
            nebula.session.geolocation.accuracy.color = '#00bb00';
            ga('set', nebula.analytics.dimensions.geoAccuracy, 'Excellent (<50m)');
        } else if ( nebula.session.geolocation.accuracy.meters > 50 && nebula.session.geolocation.accuracy.meters < 300 ){
            nebula.session.geolocation.accuracy.color = '#a4ed00';
            ga('set', nebula.analytics.dimensions.geoAccuracy, 'Good (50m - 300m)');
        } else if ( nebula.session.geolocation.accuracy.meters > 300 && nebula.session.geolocation.accuracy.meters < 1500 ){
            nebula.session.geolocation.accuracy.color = '#ffc600';
            ga('set', nebula.analytics.dimensions.geoAccuracy, 'Poor (300m - 1500m)');
        } else {
            nebula.session.geolocation.accuracy.color = '#ff1900';
            ga('set', nebula.analytics.dimensions.geoAccuracy, 'Very Poor (>1500m)');
        }
    
        nebula.addressLookup(position.coords.latitude, position.coords.longitude);
    
        sessionStorage['nebulaSession'] = JSON.stringify(nebula.session);
        nebula.dom.document.trigger('geolocationSuccess', nebula.session.geolocation);
        nebula.dom.body.addClass('geo-latlng-' + nebula.session.geolocation.coordinates.latitude.toFixed(4).replace('.', '_') + '_' + nebula.session.geolocation.coordinates.longitude.toFixed(4).replace('.', '_') + ' geo-acc-' + nebula.session.geolocation.accuracy.meters.toFixed(0).replace('.', ''));
        ga('set', nebula.analytics.dimensions.geolocation, nebula.session.geolocation.coordinates.latitude.toFixed(4) + ', ' + nebula.session.geolocation.coordinates.longitude.toFixed(4));
        ga('send', 'event', 'Geolocation', nebula.session.geolocation.coordinates.latitude.toFixed(4) + ', ' + nebula.session.geolocation.coordinates.longitude.toFixed(4), 'Accuracy: ' + nebula.session.geolocation.accuracy.meters.toFixed(2) + ' meters');
        nebula.crm('identify', {'geolocation': nebula.session.geolocation.coordinates.latitude.toFixed(4) + ', ' + nebula.session.geolocation.coordinates.longitude.toFixed(4) + ' (Accuracy: ' + nebula.session.geolocation.accuracy.meters.toFixed(2) + ' meters'});
    }
    

    Override

    To override or disable this JavaScript function, simply redeclare it with the exact same function name.

    JavaScript
    function geoSuccessCallback(){
        //Write your own code here, leave it blank, or return false.
    }