Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Incorrect parsed name from Google Maps api

Open
#1,077 8 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
48/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
php
Domain
api, backend

Research direction

Start in GoogleMaps.php around line 235 and trace how address_components are mapped into the returned object. Reproduce the Pershagen and Ronna searches, then verify that the parsed name is correct for both cases and that other address-component results are not regressed.

Written by the indexing model from the issue text.

Description

provider

Searching for Pershagen returns the following json
https://maps.googleapis.com/maps/api/geocode/json?address=Pershagen&key=xxx

{
   "results" : [
      {
         "address_components" : [
            {
               "long_name" : "Pershagen",
               "short_name" : "Pershagen",
               "types" : [ "locality", "political" ]
            },
            {
               "long_name" : "Södertälje",
               "short_name" : "Södertälje",
               "types" : [ "postal_town" ]
            },
            {
               "long_name" : "Stockholm County",
               "short_name" : "Stockholm County",
               "types" : [ "administrative_area_level_1", "political" ]
            },
            {
               "long_name" : "Sweden",
               "short_name" : "SE",
               "types" : [ "country", "political" ]
            },
            {
               "long_name" : "151 39",
               "short_name" : "151 39",
               "types" : [ "postal_code" ]
            }
         ],
         "formatted_address" : "151 39 Pershagen, Sweden",
         "geometry" : {
            "location" : {
               "lat" : 59.14664239999999,
               "lng" : 17.6511284
            },
            "location_type" : "APPROXIMATE",
            "viewport" : {
               "northeast" : {
                  "lat" : 59.15236419999999,
                  "lng" : 17.6671358
               },
               "southwest" : {
                  "lat" : 59.1409196,
                  "lng" : 17.635121
               }
            }
         },
         "place_id" : "ChIJV_Hb5dUSX0YRULaMsvX-AAo",
         "types" : [ "locality", "political" ]
      }
   ],
   "status" : "OK"
}

Using the google maps provider I get the following object. The phrase Pershagen is omitted.
image

Searching for the similar area Ronna I get a more correct object.
image

When looping over address components Pershagen is first set but then overridden by Södertälje.

Reversing the array on L235 in GoogleMaps.php returns a more accurate result.

+foreach (array_reverse($result->address_components) as $component) {
-foreach ($result->address_components as $component) {

image

Not at all sure how this will affect other results!

Dominant language
PHP
Stars
4k
Forks
525
Avg merge
8m
Merged PRs (30d)
1

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from geocoder-php/Geocoder

All issues in geocoder-php/Geocoder

Similar issues

More PHP issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.