react-native-geocoder icon indicating copy to clipboard operation
react-native-geocoder copied to clipboard

Enable geocoding via google services

Open avdept opened this issue 7 years ago • 6 comments

Force geocoder to use google geocoding service. Why need this ? My ios and android app geocoding returns slightly different results. For ex. - 1 Orange St on IOS and 1 Orange street on android, which is caused by different geocoders. Thus, if you need consistency - forcing to use google geocoder.

avdept avatar May 16 '17 19:05 avdept

Bump to this, good idea 👍

ryancoughlin avatar Jun 06 '17 23:06 ryancoughlin

@avdept Did this solve the geocoder failing for you? I am going to checkout this branch later and try it out. simulator screen shot jun 12 2017 10 14 57 am

export function geoCodeLocation(location) {
  return new Promise((resolve) => {
    const { latitude, longitude } = location

    if (location) {
      Geocoder.fallbackToGoogle(process.env.GOOGLE_GEOCODE_API)
      Geocoder.geocodePosition({ lat: latitude, lng: longitude })
        .then((userLocation) => {
          if (userLocation[0].locality) {
            alert(userLocation[0].locality)
            resolve(userLocation[0].locality)
          }
        })
        .catch((e) => {
          alert(e)
          Alert.alert(
            'Cannot find city name',
            'We were unable to geocode your position. Tide and weather conditions will be accurate.',
            [{ text: 'OK' }],
          )
        })
    } else {
      alert('NO LOCATION YET!!!!!!')
    }
  })
}

Been trying to catch a few cases (if they in fact exist), but everything seems correct. Was thinking it was sending it twice, but it's not.

ryancoughlin avatar Jun 12 '17 14:06 ryancoughlin

Nice! How's it going with this PR?

nonameolsson avatar Jul 11 '17 20:07 nonameolsson

I would add fallback to standard geocoder if google fails. Does it make sense?

alvelig avatar Aug 14 '17 22:08 alvelig

@ryancoughlin I didnt face error like yours. Did you manage to handle it?

@alvelig I think it makes sense if google geocoder was default. In this case you forcing to use only google geocoder, so you should take care about handling errors. But In general its pretty easy to refactor. If anybody else will need it, I will add handler for google geocode failure.

avdept avatar Sep 06 '17 15:09 avdept

Not yet, it happens every now and then. I can't seem to find a pattern for it. I have the fallback in there as well.

ryancoughlin avatar Sep 06 '17 16:09 ryancoughlin