Skip to content
This repository has been archived by the owner on Sep 4, 2021. It is now read-only.

Enable geocoding via google services #48

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Enable geocoding via google services #48

wants to merge 2 commits into from

Conversation

avdept
Copy link

@avdept avdept commented May 16, 2017

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.

@ryancoughlin
Copy link

Bump to this, good idea 👍

@ryancoughlin
Copy link

@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.

@nonameolsson
Copy link

Nice! How's it going with this PR?

@alvelig
Copy link

alvelig commented Aug 14, 2017

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

@avdept
Copy link
Author

avdept commented Sep 6, 2017

@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.

@ryancoughlin
Copy link

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.

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

Successfully merging this pull request may close these issues.

None yet

4 participants