-2

I am receiving many times only types plus_code for my google map requests. I have a code which fetches the administrative_area_3 2 or locality and am not interested in plus codes.

I do reverse geocode for particular coordinates.

One such example is the point with lat lng '42.6552808', '20.4036742',

for which reverse geocode returns

{
  "plus_code" :
  {
    "global_code" : "8GJ2MC43+4F7"
  },
  "results" :
  [
    {
      "address_components" :
      [
        {
          "long_name" : "8GJ2MC43+4F",
          "short_name" : "8GJ2MC43+4F",
          "types" :
          [
            "plus_code"
          ]
        }
      ],
      "formatted_address" : "8GJ2MC43+4F",
      "geometry" :
      {
        "bounds" :
        {
          "northeast" :
          {
            "lat" : 42.655375,
            "lng" : 20.40375
          },
          "southwest" :
          {
            "lat" : 42.65525,
            "lng" : 20.403625
          }
        },
        "location" :
        {
          "lat" : 42.6552808,
          "lng" : 20.4036742
        },
        "location_type" : "GEOMETRIC_CENTER",
        "viewport" :
        {
          "northeast" :
          {
            "lat" : 42.6566614802915,
            "lng" : 20.4050364802915
          },
          "southwest" :
          {
            "lat" : 42.6539635197085,
            "lng" : 20.4023385197085
          }
        }
      },
      "place_id" : "GhIJLtnCPeBTRUARLD0_MVdnNEA",
      "plus_code" :
      {
        "global_code" : "8GJ2MC43+4F"
      },
      "types" :
      [
        "plus_code"
      ]
    }
  ],
  "status" : "OK"
}

My php code for the request is

$this->httpClient->get(
            'https://maps.googleapis.com/maps/api/geocode/json,
            [
                RequestOptions::HTTP_ERRORS => false,
                RequestOptions::QUERY => [
                    'key' => 'mykey',
                    'latlng' => sprintf('%s,%s', $latitude, $longitude),
                    'components' => 'country|locality',
                    'language' => (string)$locale
                ]
            ]
        );

There is only 1 result of type plus_code, no other results with locality, administrative area or something more "meaningful" like a containing entity.

So the question is:

How can I get the city/village/locality/whateveradmare of some location when I get back only a plus code in the response?

My thoughts atm: Just try reverse geocode with some km distance nearby in a while loop until i get back the next division

Kristi Jorgji
  • 1,154
  • 1
  • 14
  • 39
  • What does your request look like? – geocodezip Aug 25 '23 at 12:51
  • @geocodezip updated my post with php code and query params added to the request – Kristi Jorgji Aug 25 '23 at 13:37
  • Those coordinates are in Kosovo, a disputed region. Possible duplicate of [Google Map Api Return Zero Results](https://stackoverflow.com/questions/39510860/google-map-api-return-zero-results) or [unable to get administrative_level_1 information for border areas in india](https://stackoverflow.com/questions/32583459/unable-to-get-administrative-level-1-information-for-border-areas-in-india) – geocodezip Aug 26 '23 at 15:03
  • Ok thanks for the insights. I understand that a disputed region might not have a country, but I don't understand that it does not have any bigger container for example village,municipality etc. Anyway thanks for the insight I will make some checks in my code for this cases where I get back only plus code and ignore them or search +- some km nearby until I get a proper response and not just a plus code which has no meaningful name – Kristi Jorgji Aug 27 '23 at 08:18

0 Answers0