Giter Club home page Giter Club logo

Comments (6)

LeeroyJenks avatar LeeroyJenks commented on July 29, 2024 3

I did a little hacky fix in the function getCity()
from this:

function getCity(place) {
    var COMPONENT_TEMPLATE = { locality: 'long_name' },
        city = getAddrComponent(place, COMPONENT_TEMPLATE);
    return city;
}

to this

function getCity(place) {
    var COMPONENT_TEMPLATE = { locality: 'long_name' },
        city = getAddrComponent(place, COMPONENT_TEMPLATE);
      if (!city || city == '') {
        COMPONENT_TEMPLATE = { sublocality_level_1: 'long_name'},
        city = getAddrComponent(place, COMPONENT_TEMPLATE);
      }
    return city;
}

I'm sure you can come up with a better fix, but I just wanted something quick for my application.

from vsgoogleautocomplete.

vskosp avatar vskosp commented on July 29, 2024

Hi!

  1. In the Google Maps JavaScript API documentation about restriction of autocomplete results is written the next: "...The (cities) type collection instructs the Places service to return results that match locality or administrative_area_level_3..."
  2. In the Google Places API example, where it is shown how to parse address components, only locality type used for getting the city.
  3. When I got place details for Brooklyn through the autocomplete, I have gotten New York city in the address component.

Write, if I understood something wrong.

If you need to get information about sublocality, I can add a new directive for parsing this address component.

Thanks you!

from vsgoogleautocomplete.

LeeroyJenks avatar LeeroyJenks commented on July 29, 2024

Hey!
Thanks for the quick response. I think the issue is really with special areas that use sublocalities as cities.
The NYC area tends to be one of those, so locality actually displays nothing.
I'm using "384 Court Street Brooklyn NY United States" as an example.
When I log all possible "address_components" types, I get this list:

street_number
route
neighborhood
political
sublocality_level_1
sublocality
political
administrative_area_level_2
political
administrative_area_level_1
political
country
political
postal_code
postal_code_suffix

You'll notice in this list that "locality" and "administrative_area_level_3" are not found in that list, so when attempting to get the city using those types, the outcome is undefined. I think this is an oversight on Google's part, and something I'll make sure to bring to their attention.
I just wanted to bring it to your attention as well!

Just to be clear, this is the function that is being called to get an address component (via vs-street, vs-city, etc...):

function getAddrComponent(place, componentTemplate) {
    var result;
    if (!isGooglePlace(place))
        return;
    for (var i = 0; i < place.address_components.length; i++) {
        var addressType = place.address_components[i].types[0];
        if (componentTemplate[addressType]) {
            result = place.address_components[i][componentTemplate[addressType]];
            return result;
        }
    }
    return;
}

from vsgoogleautocomplete.

vskosp avatar vskosp commented on July 29, 2024

I think, that detailed information of place for this address("384 Court Street Brooklyn NY United States") is not full. It should contain component with type: "locality" and short/long name: "NY/New York".

I can only add directives, which will parse place details object for getting additional information about input address.

from vsgoogleautocomplete.

LeeroyJenks avatar LeeroyJenks commented on July 29, 2024

Yeah I agree. The issue is that I tried it with a few addresses in Brooklyn, and it was the same issue. It is either incomplete, or google is using a structure that they have not documented for places like New York City.
Since my application is highly centered around New York, I have added my previously-mentioned script to account for those issues.
Thanks!

from vsgoogleautocomplete.

roydukkey avatar roydukkey commented on July 29, 2024

Brooklyn and other parts of New York City do not include the city as part of the address. They use sublocality_level_1 instead.

Google documents that NYC is different on their Place Autocomplete Address Form example.

from vsgoogleautocomplete.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.