node-geocoder
node-geocoder copied to clipboard
City is null when searching address in NYC
This will return
await geocoder.geocode({
'407 Adams Ave',
'US',
});
[
{
formattedAddress: '407 Adams Ave, Staten Island, NY 10306, USA',
latitude: 40.5771522,
longitude: -74.0931513,
extra: {
googlePlaceId: 'ChIJyfCeIsxOwokRuU1h1tTLLIs',
confidence: 1,
premise: null,
subpremise: null,
neighborhood: 'Midland Beach',
establishment: null
},
administrativeLevels: {
level2long: 'Richmond County',
level2short: 'Richmond County',
level1long: 'New York',
level1short: 'NY'
},
streetNumber: '407',
streetName: 'Adams Avenue',
country: 'United States',
countryCode: 'US',
zipcode: '10306',
provider: 'google'
}
]
I have a service that depends on having the city
field populated
Hi @brandonbryant12 Looks like google geocoder do not return a locality
component for that address what is the expected city here? to see if we can improve it and find a good fallback if there is no locality
Hi @brandonbryant12 Looks like google geocoder do not return a
locality
component for that address what is the expected city here? to see if we can improve it and find a good fallback if there is no locality
This is in Staten Island NYC. Experienced the same thing for a user in the Bronx. I think it's a NYC thing afaik
The result from google geocoder looks like this maybe we can use the sublocality
as a fallback, but it need a little more investigation to be sure it's a safe fallback
"results" : [
{
"address_components" : [
{
"long_name" : "407",
"short_name" : "407",
"types" : [ "street_number" ]
},
{
"long_name" : "Adams Avenue",
"short_name" : "Adams Ave",
"types" : [ "route" ]
},
{
"long_name" : "Midland Beach",
"short_name" : "Midland Beach",
"types" : [ "neighborhood", "political" ]
},
{
"long_name" : "Staten Island",
"short_name" : "Staten Island",
"types" : [ "political", "sublocality", "sublocality_level_1" ]
},
{
"long_name" : "Richmond County",
"short_name" : "Richmond County",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "New York",
"short_name" : "NY",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "United States",
"short_name" : "US",
"types" : [ "country", "political" ]
},
{
"long_name" : "10306",
"short_name" : "10306",
"types" : [ "postal_code" ]
},
{
"long_name" : "5237",
"short_name" : "5237",
"types" : [ "postal_code_suffix" ]
}
],
"formatted_address" : "407 Adams Ave, Staten Island, NY 10306, USA",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 40.5781923,
"lng" : -74.09489739999999
},
"southwest" : {
"lat" : 40.5780057,
"lng" : -74.09511169999999
}
},
"location" : {
"lat" : 40.5781315,
"lng" : -74.0949888
},
"location_type" : "ROOFTOP",
"viewport" : {
"northeast" : {
"lat" : 40.5794094302915,
"lng" : -74.0936871697085
},
"southwest" : {
"lat" : 40.5767114697085,
"lng" : -74.09638513029151
}
}
},
"place_id" : "ChIJ0XTVVclOwokR7QkAK-R0HTc",
"types" : [ "premise" ]
}
]
Looks like it could work