react-native-geocoder
react-native-geocoder copied to clipboard
Enable geocoding via google services
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.
Bump to this, good idea 👍
@avdept Did this solve the geocoder failing for you? I am going to checkout this branch later and try it out.
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.
Nice! How's it going with this PR?
I would add fallback to standard geocoder if google fails. Does it make sense?
@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.
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.