Skip to content
This repository was archived by the owner on Nov 8, 2017. It is now read-only.
18 changes: 13 additions & 5 deletions jquery.geocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@

// See: [Geocoding Types](https://developers.google.com/maps/documentation/geocoding/#Types)
// on Google Developers.
var componentTypes = ("street_address route intersection political " +
var componentTypes = ("street_address route street_address_only intersection political " +
"country administrative_area_level_1 administrative_area_level_2 " +
"administrative_area_level_3 colloquial_area locality sublocality " +
"neighborhood premise subpremise postal_code natural_feature airport " +
Expand Down Expand Up @@ -363,15 +363,17 @@

// Set the values for all details.
$.each(this.details, $.proxy(function(key, $detail){
var value = data[key];
var value = (key !== "street_address_only") ? data[key] : data["street_number"] + " " + data["route"];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately the layout will depend on the country. In some places it is route number in other places number route or number, route.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that different regions need different street address formats. Addresses are one of the largest headaches I've come across. I think it would be a good option for a user of this plugin to be able to fill the desired form field with the street address of their choice. I would propose to either offer multiple format types, such as street_number_route, route_street_number, etc., or give the option for multiple types in the data attribute on the input. For example, data-geo="street_number route" which would fill with "123 Main St" or data-geo="route street_number" which would fill with "Main St 123". It at least still gives the option for the user of the plugin to use the street address in the format they choose. I think the second option is cleaner. If either option is something you'd like to merge into the plugin, I'll see what I can do to get it done.

this.setDetail($detail, value);
}, this));

this.data = data;
},

// Assign a given `value` to a single `$element`.
// If the element is an input, the value is set, otherwise it updates
// If the element is an input, the value is set, if the element is a
// select, it checks the value and text fields of its options and
// selects the matching option if it exists, otherwise it updates
// the text content.
setDetail: function($element, value){

Expand All @@ -382,8 +384,14 @@
}

if ($element.is(":input")){
$element.val(value);
} else {
if($element.is("select")){
$element.find("option").filter(function(){
return ( ($(this).val() == value) || ($(this).text() == value) )
}).prop('selected', true);
}
else
$element.val(value);
} else {
$element.text(value);
}
},
Expand Down