[TriLUG] Google Maps Autocomplete help?

Wes Garrison via TriLUG trilug at trilug.org
Tue Sep 4 23:07:38 EDT 2018


Brian, are you parsing the places or creating places?

Here's a list of the types:
https://developers.google.com/places/supported_types

According to that, you can't use the "country" type when searching for a
place or adding a place.

Here's what I use to parse through it:

google.maps.event.addListener(autocomplete, 'place_changed', function() {
place = autocomplete.getPlace();
if (!place.geometry) {
return false;
}

for (var i = 0; i < place.address_components.length; i++) {
var addressType = place.address_components[i].types[0];
if (addressType === 'street_number') {
streetno = place.address_components[i].short_name;
}
if (addressType === 'route') {
route = place.address_components[i].short_name;
}
if (addressType === 'locality') {
city = place.address_components[i].short_name;
}
if (addressType === 'administrative_area_level_1') {
state = place.address_components[i].short_name;
}
if (addressType === 'postal_code') {
zip = place.address_components[i].short_name;
}
if (addressType === 'country') {
country = place.address_components[i].short_name;
}
}

It should work for parsing by country.

-Wes
_________________________________
Wesley S. Garrison
Network Engineer
Xitech Communications, Inc.
phone:  (919) 260-0803
fax:       (919) 932-5051
__________________________________
"Lead us not into temptation, but deliver us from email."


On Tue, Sep 4, 2018 at 9:02 PM Brian McCullough via TriLUG <
trilug at trilug.org> wrote:

> Folks,
>
> I have run into a bit of a quandry, and expect that this oracle can help
> me.
>
>
> I have been learning to use Google's Autocomplete for a current project.
>
> Doing this, I have encountered a small stumbling block.  According to my
> reading of the documentation, one of the "place types" is "country."  I
> have been successful with "(cities)," but "country" fails.  In fact, I
> have only been successful with "(regions)" to find Countries, and that,
> of course, is not ideal, because it comes back with States, Provinces
> and Cities, as well as Countries.
>
> Any suggestions, or is the documentation just wrong?
>
>
>
> Thank you,
> Brian
>
> --
> This message was sent to: Wes <wes at xitechusa.com>
> To unsubscribe, send a blank message to trilug-leave at trilug.org from that
> address.
> TriLUG mailing list : https://www.trilug.org/mailman/listinfo/trilug
> Unsubscribe or edit options on the web  :
> https://www.trilug.org/mailman/options/trilug/wes%40xitechusa.com
> Welcome to TriLUG: https://trilug.org/welcome


More information about the TriLUG mailing list