jquery.geocomplete.js
function(){

      // Indicates is user did select a result from the dropdown.
      var selected = false;

      var options = {
        types: this.options.types,
        bounds: this.options.bounds === true ? null : this.options.bounds,
        componentRestrictions: this.options.componentRestrictions,
        strictBounds: this.options.strictBounds
      };

      if (this.options.country){
        options.componentRestrictions = {country: this.options.country};
      }

      this.autocomplete = new google.maps.places.Autocomplete(
        this.input, options
      );

      this.geocoder = new google.maps.Geocoder();

      // Bind autocomplete to map bounds but only if there is a map
      // and `options.bindToMap` is set to true.
      if (this.map && this.options.bounds === true){
        this.autocomplete.bindTo('bounds', this.map);
      }

      // Watch `place_changed` events on the autocomplete input field.
      google.maps.event.addListener(
        this.autocomplete,
        'place_changed',
        $.proxy(this.placeChanged, this)
      );

      // Prevent parent form from being submitted if user hit enter.
      this.$input.on('keypress.' + this._name, function(event){
        if (event.keyCode === 13){ return false; }
      });

      // Assume that if user types anything after having selected a result,
      // the selected location is not valid any more.
      if (this.options.geocodeAfterResult === true){
        this.$input.bind('keypress.' + this._name, $.proxy(function(){
          if (event.keyCode != 9 && this.selected === true){
              this.selected = false;
          }
        }, this));
      }

      // Listen for "geocode" events and trigger find action.
      this.$input.bind('geocode.' + this._name, $.proxy(function(){
        this.find();
      }, this));

      // Saves the previous input value
      this.$input.bind('geocode:result.' + this._name, $.proxy(function(){
        this.lastInputVal = this.$input.val();
      }, this));

      // Trigger find action when input element is blurred out and user has
      // not explicitly selected a result.
      // (Useful for typing partial location and tabbing to the next field
      // or clicking somewhere else.)
      if (this.options.blur === true){
        this.$input.on('blur.' + this._name, $.proxy(function(){
          if (this.options.geocodeAfterResult === true && this.selected === true) { return; }

          if (this.options.restoreValueAfterBlur === true && this.selected === true) {
            setTimeout($.proxy(this.restoreLastValue, this), 0);
          } else {
            this.find();
          }
        }, this));
      }
    }
function(){

      // Indicates is user did select a result from the dropdown.
      var selected = false;

      var options = {
        types: this.options.types,
        bounds: this.options.bounds === true ? null : this.options.bounds,
        componentRestrictions: this.options.componentRestrictions,
        strictBounds: this.options.strictBounds
      };

      if (this.options.country){
        options.componentRestrictions = {country: this.options.country};
      }

      this.autocomplete = new google.maps.places.Autocomplete(
        this.input, options
      );

      this.geocoder = new google.maps.Geocoder();

      // Bind autocomplete to map bounds but only if there is a map
      // and `options.bindToMap` is set to true.
      if (this.map && this.options.bounds === true){
        this.autocomplete.bindTo('bounds', this.map);
      }

      // Watch `place_changed` events on the autocomplete input field.
      google.maps.event.addListener(
        this.autocomplete,
        'place_changed',
        $.proxy(this.placeChanged, this)
      );

      // Prevent parent form from being submitted if user hit enter.
      this.$input.on('keypress.' + this._name, function(event){
        if (event.keyCode === 13){ return false; }
      });

      // Assume that if user types anything after having selected a result,
      // the selected location is not valid any more.
      if (this.options.geocodeAfterResult === true){
        this.$input.bind('keypress.' + this._name, $.proxy(function(){
          if (event.keyCode != 9 && this.selected === true){
              this.selected = false;
          }
        }, this));
      }

      // Listen for "geocode" events and trigger find action.
      this.$input.bind('geocode.' + this._name, $.proxy(function(){
        this.find();
      }, this));

      // Saves the previous input value
      this.$input.bind('geocode:result.' + this._name, $.proxy(function(){
        this.lastInputVal = this.$input.val();
      }, this));

      // Trigger find action when input element is blurred out and user has
      // not explicitly selected a result.
      // (Useful for typing partial location and tabbing to the next field
      // or clicking somewhere else.)
      if (this.options.blur === true){
        this.$input.on('blur.' + this._name, $.proxy(function(){
          if (this.options.geocodeAfterResult === true && this.selected === true) { return; }

          if (this.options.restoreValueAfterBlur === true && this.selected === true) {
            setTimeout($.proxy(this.restoreLastValue, this), 0);
          } else {
            this.find();
          }
        }, this));
      }
    }
function ( ) { // Indicates is user did select a result from the dropdown. var selected = false ; var options = { types : this . options . types , bounds : this . options . bounds === true ? null : this . options . bounds , componentRestrictions : this . options . componentRestrictions , strictBounds : this . options . strictBounds } ; if ( this . options . country ) { options . componentRestrictions = { country : this . options . country } ; } this . autocomplete = new google . maps . places . Autocomplete ( this . input , options ) ; this . geocoder = new google . maps . Geocoder ( ) ; // Bind autocomplete to map bounds but only if there is a map // and `options.bindToMap` is set to true. if ( this . map && this . options . bounds === true ) { this . autocomplete . bindTo ( 'bounds' , this . map ) ; } // Watch `place_changed` events on the autocomplete input field. google . maps . event . addListener ( this . autocomplete , 'place_changed' , $ . proxy ( this . placeChanged , this ) ) ; // Prevent parent form from being submitted if user hit enter. this . $input . on ( 'keypress.' + this . _name , function ( event ) { if ( event . keyCode === 13 ) { return false ; } } ) ; // Assume that if user types anything after having selected a result, // the selected location is not valid any more. if ( this . options . geocodeAfterResult === true ) { this . $input . bind ( 'keypress.' + this . _name , $ . proxy ( function ( ) { if ( event . keyCode != 9 && this . selected === true ) { this . selected = false ; } } , this ) ) ; } // Listen for "geocode" events and trigger find action. this . $input . bind ( 'geocode.' + this . _name , $ . proxy ( function ( ) { this . find ( ) ; } , this ) ) ; // Saves the previous input value this . $input . bind ( 'geocode:result.' + this . _name , $ . proxy ( function ( ) { this . lastInputVal = this . $input . val ( ) ; } , this ) ) ; // Trigger find action when input element is blurred out and user has // not explicitly selected a result. // (Useful for typing partial location and tabbing to the next field // or clicking somewhere else.) if ( this . options . blur === true ) { this . $input . on ( 'blur.' + this . _name , $ . proxy ( function ( ) { if ( this . options . geocodeAfterResult === true && this . selected === true ) { return ; } if ( this . options . restoreValueAfterBlur === true && this . selected === true ) { setTimeout ( $ . proxy ( this . restoreLastValue , this ) , 0 ) ; } else { this . find ( ) ; } } , this ) ) ; } }
Associate the input with the autocompleter and create a geocoder to fall back when the autocompleter does not return a value.
Associate the input with the autocompleter and create a geocoder to fall back when the autocompleter does not return a value .