kuhnza / angular-google-places-autocomplete

Pure AngularJS directive for Google Places Autocomplete
MIT License
257 stars 189 forks source link

Converting Places to Address #60

Open swapnil002 opened 9 years ago

swapnil002 commented 9 years ago

Hey,

When I am selecting "Times Square NY" from dropdown, it is getting converted to "Manhattan, NY 10036, United States" .

But i want to display "Times Square NY" only. Please help.

kamikaz1k commented 8 years ago

Trying to solve the same problem...Did you get anywhere with this?

kamikaz1k commented 8 years ago

Figured it out.

In the directive's format(modelValue) function the viewValue is set. Simply change the value in the else if clause like so: viewValue = modelValue.name; (line 225)

.name can be changed to any other place attribute you may want to set it as.

alecgibson commented 8 years ago

I verify this solution. I've changed the whole block to look like this:

if (isString(modelValue)) {
    viewValue = modelValue;
} else if (isObject(modelValue)) {
    if (isString(modelValue.name)) {
        viewValue = modelValue.name;
    } else {
        viewValue = modelValue.formatted_address;
    }
}
jrhite commented 8 years ago

I've seen this code too, but is there a hook to configure this? I don't want to rewrite the code. I just want to pass in an option to the angular-google-places-autocomplete directive to tell it what field on the 'place' to use.

Is it possible to configure it for this? If so, how?

nbpayne commented 8 years ago

I issued a merge request to address this issue, but it hasn't been merged yet.

You can grab my version from here: https://github.com/nbpayne/angular-google-places-autocomplete

Add this to your bower.json.

"angular-google-places-autocomplete": "https://github.com/nbpayne/angular-google-places-autocomplete.git#500dcbc"
aamirkhan-91 commented 7 years ago

This feature should really be merged. It's essential.

ary-ana commented 7 years ago

Just ran into the same issue. Seems like this fix should be the default - confusing for the user to have the input value not show the name of the place that was selected.