Skip to Content

placeLookup()

Attempt to look up a business by Place ID via Google Maps Place Service.

JavaScript February 22, 2017

Usage

JavaScript
placeLookup(placeID)

Parameters

placeID
(Required) (String) The place ID to look up.
Default: None

Request or provide clarification »

Examples

Called after a successful (and accurate) address lookup from Google Maps.

JavaScript
placeLookup(results[0].place_id);

Additional Notes

This function triggers placeSuccess on success when the nebula.session.geolocation.address.place object can be used.

Source File

Located in /assets/js/nebula.js on line 3403.

Note: This function contains 1 to-do comment.

JavaScript
nebula.placeLookup = function(placeID){
    if ( nebula.has(google, 'maps.places') ){ //@todo "Nebula" 0: Replace with optional chaining
        var service = new google.maps.places.PlacesService(jQuery('<div></div>').get(0));
        service.getDetails({
            placeId: placeID
        }, function(place, status){
            if ( status === google.maps.places.PlacesServiceStatus.OK ){
                if ( typeof place.name !== 'undefined' ){
                    nebula.session.geolocation.address.place = {
                        id: placeID,
                        name: place.name,
                        url: place.url,
                        website: place.website,
                        phone: place.formatted_phone_number,
                        ratings: {
                            rating: place.rating,
                            total: place.user_ratings_total,
                            reviews: ( typeof place.reviews !== 'undefined' )? place.reviews.length : 0,
                        },
                        utc_offset: place.utc_offset,
                    };

                    sessionStorage['nebulaSession'] = JSON.stringify(nebula.session);
                    nebula.dom.document.trigger('placeSuccess');
                }
            }
        });
    }
};

Override

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

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