seripap / Google-Geocode-Parser

This is a utility to help parse raw geocoded data returned from Google Geocode API services.
1 stars 5 forks source link

City is sometimes null #8

Open mtimofiiv opened 5 years ago

mtimofiiv commented 5 years ago

Hello! This is more of an issue with how Google tags its locations than this module, but it does have sometimes inconsistent behaviour when it comes to getting city names.

The reason is that locality or sublocality is not always present. Take for example the following GPS coords:

16.052453531265428,108.24288435280323

This set of coords is smack in the middle of Da Nang city in Vietnam. I posted the result set below (filtered for locality since those are the relevant ones), so you can see there's no locality set on it. However, it seems the administrative_area_level_1/political result has that info in it.

To be honest I am not sure how many places are affected, but searching coordinates in Ho Chi Minh City yielded the same results: no locality, only administrative_area_level_1/political having the name of the city in it.

Obviously I can't expect this module to fix something in Google's tagging mechanism but it might be nice to brainstorm what can be done here instead?

{
  "plus_code": {
    "compound_code": "362V+X5 My An, Ngũ Hành Sơn, Da Nang, Vietnam",
    "global_code": "7P8C362V+X5"
  },
  "results": [],
  "status": "ZERO_RESULTS"
}

Now the reason for this might be that Da Nang is also technically the province name as well.

kalnode commented 1 year ago

From what I can tell, this plugin does fine-grained interpretation of what data can be deemed "City":

  isCity() {
    return this.isType(['locality', 'sublocality', 'political', 'sublocality_level_1', 'sublocality_level_2', 'sublocality_level_3', 'sublocality_level_4', 'sublocality_level_5']);
  }

So getting city as null likely means that that particular place really is exceptional, if it doesn't have anything for all those fields.

Maybe this is a case of city-states, like Washington DC or The Vatican; am I using the right analogy?

In any case, perhaps it should not matter, because in your application, for safety, you should build in a condition to handle this. If there's no city result, then fallback to state?

This plugin has a function using administrative_area_level_1:

  isState() {
    return this.isType(['administrative_area_level_1']);
  }