dist/utilify.esm.js
function getUserLocation(cache, storage) {
        var _this = this;

        if (cache) {
            this._initLocationStorage(storage);
        }

        var store = storage.session.get(CONSTANTS.STORAGE_NAME);

        /* eslint-disable */
        return $.Deferred(function (def) {
            /* eslint-enable */
            if (!validateHelpers.isObjectEmpty(store)) {
                def.resolve(store);
            } else {
                if (window.navigator.geolocation) {
                    navigator.geolocation.getCurrentPosition(function (position) {
                        var lat = position.coords.latitude;
                        var lng = position.coords.longitude;

                        if (!window.google) {
                            return def.reject('Google Maps Javascript API not found. Follow tutorial: https://developers.google.com/maps/documentation/javascript');
                        }

                        var latlng = new google.maps.LatLng(lat, lng);
                        var geocoder = new google.maps.Geocoder();

                        geocoder.geocode({ 'latLng': latlng }, function (results, status) {
                            if (status === google.maps.GeocoderStatus.OK) {
                                if (results[1]) {
                                    for (var i = 0, len = results.length; i < len; i += 1) {
                                        if (results[i].types[0] === 'locality') {
                                            var city = results[i].address_components[0].short_name;
                                            var state = results[i].address_components[2].short_name;
                                            var storeLocation = {
                                                coords: { lat: lat, lng: lng },
                                                city: city,
                                                state: state,
                                                region: _this.filteredRegion(state)
                                            };

                                            if (cache) {
                                                storage.session.set(CONSTANTS.STORAGE_NAME, storeLocation, CONSTANTS.EXPIRE_TIME);
                                            }

                                            def.resolve(storeLocation);
                                        }
                                    }
                                } else {
                                    def.reject('No reverse geocode results.');
                                }
                            } else {
                                def.reject('Geocoder failed: ' + status);
                            }
                        });
                    }, function (err) {
                        def.reject('Geolocation not available.');
                    });
                } else {
                    def.reject('Geolocation isn\'t available');
                }
            }
        }).promise();
    }
function getUserLocation(cache, storage) {
        var _this = this;

        if (cache) {
            this._initLocationStorage(storage);
        }

        var store = storage.session.get(CONSTANTS.STORAGE_NAME);

        /* eslint-disable */
        return $.Deferred(function (def) {
            /* eslint-enable */
            if (!validateHelpers.isObjectEmpty(store)) {
                def.resolve(store);
            } else {
                if (window.navigator.geolocation) {
                    navigator.geolocation.getCurrentPosition(function (position) {
                        var lat = position.coords.latitude;
                        var lng = position.coords.longitude;

                        if (!window.google) {
                            return def.reject('Google Maps Javascript API not found. Follow tutorial: https://developers.google.com/maps/documentation/javascript');
                        }

                        var latlng = new google.maps.LatLng(lat, lng);
                        var geocoder = new google.maps.Geocoder();

                        geocoder.geocode({ 'latLng': latlng }, function (results, status) {
                            if (status === google.maps.GeocoderStatus.OK) {
                                if (results[1]) {
                                    for (var i = 0, len = results.length; i < len; i += 1) {
                                        if (results[i].types[0] === 'locality') {
                                            var city = results[i].address_components[0].short_name;
                                            var state = results[i].address_components[2].short_name;
                                            var storeLocation = {
                                                coords: { lat: lat, lng: lng },
                                                city: city,
                                                state: state,
                                                region: _this.filteredRegion(state)
                                            };

                                            if (cache) {
                                                storage.session.set(CONSTANTS.STORAGE_NAME, storeLocation, CONSTANTS.EXPIRE_TIME);
                                            }

                                            def.resolve(storeLocation);
                                        }
                                    }
                                } else {
                                    def.reject('No reverse geocode results.');
                                }
                            } else {
                                def.reject('Geocoder failed: ' + status);
                            }
                        });
                    }, function (err) {
                        def.reject('Geolocation not available.');
                    });
                } else {
                    def.reject('Geolocation isn\'t available');
                }
            }
        }).promise();
    }
function getUserLocation ( cache , storage ) { var _this = this ; if ( cache ) { this . _initLocationStorage ( storage ) ; } var store = storage . session . get ( CONSTANTS . STORAGE_NAME ) ; /* eslint-disable */ return $ . Deferred ( function ( def ) { /* eslint-enable */ if ( ! validateHelpers . isObjectEmpty ( store ) ) { def . resolve ( store ) ; } else { if ( window . navigator . geolocation ) { navigator . geolocation . getCurrentPosition ( function ( position ) { var lat = position . coords . latitude ; var lng = position . coords . longitude ; if ( ! window . google ) { return def . reject ( 'Google Maps Javascript API not found. Follow tutorial: https://developers.google.com/maps/documentation/javascript' ) ; } var latlng = new google . maps . LatLng ( lat , lng ) ; var geocoder = new google . maps . Geocoder ( ) ; geocoder . geocode ( { 'latLng' : latlng } , function ( results , status ) { if ( status === google . maps . GeocoderStatus . OK ) { if ( results [ 1 ] ) { for ( var i = 0 , len = results . length ; i < len ; i += 1 ) { if ( results [ i ] . types [ 0 ] === 'locality' ) { var city = results [ i ] . address_components [ 0 ] . short_name ; var state = results [ i ] . address_components [ 2 ] . short_name ; var storeLocation = { coords : { lat : lat , lng : lng } , city : city , state : state , region : _this . filteredRegion ( state ) } ; if ( cache ) { storage . session . set ( CONSTANTS . STORAGE_NAME , storeLocation , CONSTANTS . EXPIRE_TIME ) ; } def . resolve ( storeLocation ) ; } } } else { def . reject ( 'No reverse geocode results.' ) ; } } else { def . reject ( 'Geocoder failed: ' + status ) ; } } ) ; } , function ( err ) { def . reject ( 'Geolocation not available.' ) ; } ) ; } else { def . reject ( 'Geolocation isn\'t available' ) ; } } } ) . promise ( ) ; }
Get user location by HTML5 Geolocate API and translate coordinates to
Brazilian State, City and Region

@param {Boolean}   cache     Save user coordinates into localstorage
@param {Object}    storage   Store2 lib instance
@return {Promise}  When success, response are an object with State, City, Region and user Coordinates
@example
locationHelpers.getCityState()
.then(function(res) {
window.console.log(res);
})
.fail(function(err) {
window.console.log(err);
});
Get user location by HTML5 Geolocate API and translate coordinates to Brazilian State City and Region