Skip to content
This repository has been archived by the owner on Nov 8, 2017. It is now read-only.

Fix: copy paste the address and press enter on search-box field is not working #291

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 41 additions & 11 deletions jquery.geocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,14 +180,17 @@

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

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

if(this.options.fields) {
options.fields = this.options.fields;
}

this.autocomplete = new google.maps.places.Autocomplete(
this.input, options
);
Expand Down Expand Up @@ -330,11 +333,17 @@
});
},

findById: function(placeId){
this.geocode({
placeId: placeId
});
},

// Requests details about a given location.
// Additionally it will bias the requests to the provided bounds.
geocode: function(request){
// Don't geocode if the requested address is empty
if (!request.address) {
if (!request.address && !request.placeId) {
return;
}
if (this.options.bounds && !request.bounds){
Expand Down Expand Up @@ -373,7 +382,11 @@
firstResult += " - " + $span2;
}

this.$input.val(firstResult);
if(!!firstResult) {
this.$input.val(firstResult);
} else {
firstResult = this.$input.val();
}

return firstResult;
},
Expand Down Expand Up @@ -536,21 +549,38 @@

// Update the plugin after the user has selected an autocomplete entry.
// If the place has no geometry it passes it to the geocoder.
placeChanged: function(){
placeChanged: function() {
var place = this.autocomplete.getPlace();
this.selected = true;

if (!place.geometry){
if (!place.geometry) {
if (this.options.autoselect) {
// Automatically selects the highlighted item or the first item from the
// suggestions list.
var autoSelection = this.selectFirstResult();
this.find(autoSelection);
var autoCompleteService = this.getAutoCompleteService();
autoCompleteService.getPlacePredictions({
input: this.$input.val().split(',')[0]
}, $.proxy(this.placePredictionChange, this))
}
} else {
// Use the input text if it already gives geometry.
this.update(place);
}
},

placePredictionChange: function(result, status) {
if (status == google.maps.places.PlacesServiceStatus.OK) {
if(result.length > 0) {
this.findById(result[0].place_id);
}
} else {
this.trigger("geocode:error", status);
}
},

getAutoCompleteService: function() {
if (!this.autocompleteService) {
return this.autocompleteService = new google.maps.places.AutocompleteService();
} else {
return this.autocompleteService;
}
}
});

Expand Down
2 changes: 1 addition & 1 deletion jquery.geocomplete.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.