Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect parsed name from Google Maps api #1077

Open
jongotlin opened this issue Aug 13, 2020 · 8 comments
Open

Incorrect parsed name from Google Maps api #1077

jongotlin opened this issue Aug 13, 2020 · 8 comments
Labels

Comments

@jongotlin
Copy link

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!

@alanpoulain
Copy link

It's because of the order of these two lines:

case 'locality':
case 'postal_town':

Maybe postal_town should be before locality?

@jongotlin
Copy link
Author

@alanpoulain That won't affect the result unfortunately.

@jbelien
Copy link
Member

jbelien commented Aug 14, 2020

Thanks for the notice !
We'll need to test for address all over the world to (maybe) improve the process of locality and postal_town.
I'll try to do that ASAP.

@jongotlin For "Pershagen" search, if "Pershagen" is the locality, what should "Södertälje" be ?

@jongotlin
Copy link
Author

Ideally Pershagen would be a sub locality and Södertälje locality but thats not what the Google response says.

Can we have Södertälje in list of admin levels?

@jbelien
Copy link
Member

jbelien commented Aug 14, 2020

Can we have Södertälje in list of admin levels?

The issue is to keep a logic that works for all countries.
We only put administrative_area_level_1...5 in the admin levels list.

@jongotlin
Copy link
Author

Aha, understand. Maybe skip Södertälje in this case. The data from Google is not really correct. I think the rule here should be "If locality is set it should not be overridden by postal_town".

@jbelien
Copy link
Member

jbelien commented Aug 14, 2020

The goal of this library is to create a layer on top of (reverse) geocoding API, not fix/process/mess with the data returned by the API.

I think the rule here should be "If locality is set it should not be overridden by postal_town".

I'll make some tests for other countries in the world to see if that applies.
We won't make changes that will affect every country "just" to fix a locality issue in Sweden.

@jbelien jbelien removed the bug label Aug 14, 2020
@jongotlin
Copy link
Author

Yes, understand and agree with that. However, overriding a value like this doesn't seems correct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants