expo: Reverse geocode returns null city

🐛 Bug Report

Environment

Steps to Reproduce

Given latitude 51.65052103565574 and longitude -0.3747054375708103, the Expo reverse geocoder returns the following data - note that city is null:

Array [
  Object {
    "city": null,
    "country": "United Kingdom",
    "isoCountryCode": "GB",
    "name": "8",
    "postalCode": "WD23 2LR",
    "region": "England",
    "street": "Woodlands Road",
  },
]

However, when accessing the Google Maps Reverse Geocoding API using their test site, inputting 51.65052103565574, -0.3747054375708103’, the (formatted) address that comes up is “8 Woodlands Rd, Bushey WD23 2LR, UK”.

Note that the town (Bushey) is in the formatted address, but the city field returned to Expo was null. When I do the same using JSFiddle, I can see that Bushey is in the list of fields, as type postal_town.

image

I tried looking in the Expo source, but I’m not that familiar with it. I wonder if https://github.com/expo/expo/blob/a73494577c5006fcdaf932bc92b2b539ed57a8af/packages/expo-location/src/Location.ts#L353 is the problem - it doesn’t take postal_town into account as a possible option for city, only locality is mapped to city.

I have only been able to reproduce this with UK coordinates. According to some possibly-relevant docs:

postal_town indicates a grouping of geographic areas, such as locality and sublocality, used for mailing addresses in some countries.

Indeed, the example in the component filtering section is a UK address, with postal_town and no locality.

Reproducible Demo

I tried (see https://snack.expo.io/SkIDsoieH), but for reasons I don’t understand, geocodeText is empty. (Happy to get advice on why…)

Hope you can help and please let me know if you need any more info.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 6
  • Comments: 19 (4 by maintainers)

Most upvoted comments

I’m having the same problem, but it seems there’s any activity on this issue.

I cloned the expo-location module and replaced the part that returns the reverse geolocation, using the BigDataCloud api, until the day that the developers have the good will to solve the problem, if anyone is interested in using it feel free, But you need to uninstall the expo-location dependency and install the provisional, without having to change imports:

yarn add lucassouza16/expo-location#latest

@cmacdonnacha Just saw your answer, sorry. For the example I gave, the city (town but who’s counting) should be “Bushey”, see my browser inspector screenshot above.

This issue was closed because it has been inactive for 7 days since being marked as stale. Please open a new issue if you believe you are encountering a related problem.

This issue is stale because it has been open for 60 days with no activity. If there is no activity in the next 7 days, the issue will be closed.

I’m having the same problem, but it seems there’s any activity on this issue.

I’m facing this problem using this:

fetch('https://maps.googleapis.com/maps/api/geocode/json?address=' + location.latitude + ',' + location.longitude + '&key=' + myApiKey)
  .then((response) => response.json())
  .then((responseJson) => {
    console.log(JSON.stringify(responseJson));
  });

Hello,

I am having the same issue with locations in Sweden. I created this working snack, which shows the city for the coordinates you put in the code. For the coordinates in this example there is nothing shown. However you can see in the log, that it is known that this location is the main station of Gothenburg. https://snack.expo.io/@markuscosinus/reverse-geocoding-incomplete Coordinates: 57.709821, 11.971190

I also checked on this site. ‘Gothenburg’ is in the postal_town entry. So the Google API seems to know the places city and I guess @antgel may even be right about this:

I tried looking in the Expo source, but I’m not that familiar with it. I wonder if

expo/packages/expo-location/src/Location.ts

Line 353 in a734945 result.address_components.forEach(component => { is the problem - it doesn’t take postal_town into account as a possible option for city, only locality is mapped to city.

Everything works fine on iOS btw.

Does Expo just look at the very first address_component in the array? The reason I ask is even with London (lat: 51.507351, long: -0.127758), city is null.

I think you guys look at locality to get the city. The first address_component does not have locality but one of them does. Would it be better to loop through all to fill in all fields?

You can see here, map marker “f” has locality of “London”. https://google-developers.appspot.com/maps/documentation/utils/geocoder/#q%3D51.507351%252C-0.127758