Google Geocoder returning colloquial_area instead of administrative_area_level_2

78 Views Asked by At

I am attempting to highlight the administrative_area_level_2 using FeatureLayers and Data-driven styling

This works for most addresses, but I'm finding some outliers, for example Buckinghamshire in the UK

The process I'm using is:

  1. Geocode the address, eg postcode
  2. Filter the address_components where the types array contains administrative_area_level_2
  3. Perform a 2nd geocode request for the value in long_name

The problem I'm getting is that the 2nd response is returning "Buckinghamshire" with a type of "colloquial_area", which means that the placeId is different from the placeId provided in the FeatureStyleFunctionOptions interface, and unfortunately the interface doesn't contain a name so I can't even do some fuzzy matching...

  • Geocoded placeId: ChIJrcXUb4P3dkgRQGj8aReLCDE
  • Feature Layer placeId: ChIJ19VEWZxCdkgRnWdk0LjhNAU

Is there any way to specifically request the placeId for the administrative_area_level_2 type instead of the colloquial_area. I've attempted to use GeocoderComponentRestrictions interface, but unfortunately that doesn't affect the results returned

1st geocode response

{
  "results": [
    {
      "address_components": [
        {
          "long_name": "HP18 9JX",
          "short_name": "HP18 9JX",
          "types": [
            "postal_code"
          ]
        },
        {
          "long_name": "Menmarsh Road",
          "short_name": "Menmarsh Rd",
          "types": [
            "route"
          ]
        },
        {
          "long_name": "Worminghall",
          "short_name": "Worminghall",
          "types": [
            "locality",
            "political"
          ]
        },
        {
          "long_name": "Aylesbury",
          "short_name": "Aylesbury",
          "types": [
            "postal_town"
          ]
        },
        {
          "long_name": "Buckinghamshire",
          "short_name": "Buckinghamshire",
          "types": [
            "administrative_area_level_2",
            "political"
          ]
        },
        {
          "long_name": "England",
          "short_name": "England",
          "types": [
            "administrative_area_level_1",
            "political"
          ]
        },
        {
          "long_name": "United Kingdom",
          "short_name": "GB",
          "types": [
            "country",
            "political"
          ]
        }
      ],
      "formatted_address": "Menmarsh Rd, Worminghall, Aylesbury HP18 9JX, UK",
      "geometry": {
        "bounds": {
          "south": 51.7755669,
          "west": -1.0822505,
          "north": 51.7857449,
          "east": -1.0736626
        },
        "location": {
          "lat": 51.7795795,
          "lng": -1.0817713
        },
        "location_type": "APPROXIMATE",
        "viewport": {
          "south": 51.7755669,
          "west": -1.0822505,
          "north": 51.7857449,
          "east": -1.0736626
        }
      },
      "place_id": "ChIJvTAGuWvpdkgRw353vZxdxi8",
      "types": [
        "postal_code"
      ]
    }
  ]
}

2nd Geocode response

{
  "results": [
    {
      "address_components": [
        {
          "long_name": "Buckinghamshire",
          "short_name": "Buckinghamshire",
          "types": [
            "colloquial_area",
            "political"
          ]
        },
        {
          "long_name": "England",
          "short_name": "England",
          "types": [
            "administrative_area_level_1",
            "political"
          ]
        },
        {
          "long_name": "United Kingdom",
          "short_name": "GB",
          "types": [
            "country",
            "political"
          ]
        }
      ],
      "formatted_address": "Buckinghamshire, UK",
      "geometry": {
        "bounds": {
          "south": 51.4854818,
          "west": -1.1406962,
          "north": 52.19632319999999,
          "east": -0.4766167999999999
        },
        "location": {
          "lat": 51.8072204,
          "lng": -0.8127664
        },
        "location_type": "APPROXIMATE",
        "viewport": {
          "south": 51.4854818,
          "west": -1.1406962,
          "north": 52.19632319999999,
          "east": -0.4766167999999999
        }
      },
      "place_id": "ChIJrcXUb4P3dkgRQGj8aReLCDE",
      "types": [
        "colloquial_area",
        "political"
      ]
    }
  ]
}

Screenshot showing placeId for Buckinghamshire

0

There are 0 best solutions below