Skip to Content

addressLookup()

Attempt to (roughly) look up an address based on geolocation latitude and longitude coordinates.

JavaScript February 7, 2021

Usage

JavaScript
addressLookup(lat, lng)

Parameters

lat
(Required) (Float) Latitude
Default: None

lng
(Required) (Float) Longitude
Default: None

Request or provide clarification »

Examples

JavaScript
addressLookup('43.0537', '-76.1655');

Source File

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

No Hooks

This function does not have any filters or actions available. Request one?
JavaScript
nebula.addressLookup = function(lat, lng){
    let geocoder = new google.maps.Geocoder();
    let latlng = new google.maps.LatLng(lat, lng); //lat, lng
    geocoder.geocode({'latLng': latlng}, function(results, status){
        if ( status === google.maps.GeocoderStatus.OK ){
            if ( results ){
                nebula.session.geolocation.address = {
                    number: nebula.extractFromAddress(results[0].address_components, "street_number"),
                    street: nebula.extractFromAddress(results[0].address_components, "route"),
                    city: nebula.extractFromAddress(results[0].address_components, "locality"),
                    town: nebula.extractFromAddress(results[0].address_components, "administrative_area_level_3"),
                    county: nebula.extractFromAddress(results[0].address_components, "administrative_area_level_2"),
                    state: nebula.extractFromAddress(results[0].address_components, "administrative_area_level_1"),
                    country: nebula.extractFromAddress(results[0].address_components, "country"),
                    zip: nebula.extractFromAddress(results[0].address_components, "postal_code"),
                    formatted: results[0].formatted_address,
                    place: {
                        id: results[0].place_id,
                    },
                };
                nebula.crm('identify', {'address_lookup': results[0].formatted_address});

                sessionStorage['nebulaSession'] = JSON.stringify(nebula.session);
                nebula.dom.document.trigger('addressSuccess');
                if ( nebula.session.geolocation.accuracy.meters < 100 ){
                    nebula.placeLookup(results[0].place_id);
                }
            }
        }
    });
};

Override

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

JavaScript
nebula.addressLookup = function(lat, lng){
    //Write your own code here, leave it blank, or return false.
}