diff --git a/README.md b/README.md index 8ab2533..a0d0262 100644 --- a/README.md +++ b/README.md @@ -69,9 +69,14 @@ public class MainActivity extends ReactActivity { import Geocoder from 'react-native-geocoder'; // Position Geocoding -var NY = { +const NY = { lat: 40.7809261, - lng: -73.9637594 + lng: -73.9637594, + + // Or, keys can be latitude/longitude + + latitude: 40.7809261, + longitude: -73.9637594, }; Geocoder.geocodePosition(NY).then(res => { diff --git a/js/geocoder.js b/js/geocoder.js index 3a4563e..f79e253 100644 --- a/js/geocoder.js +++ b/js/geocoder.js @@ -11,13 +11,18 @@ export default { }, geocodePosition(position) { - if (!position || !position.lat || !position.lng) { - return Promise.reject(new Error("invalid position: {lat, lng} required")); + if (!position || (!position.lat && !position.latitude) || (!position.lng && !position.longitude)) { + return Promise.reject(new Error("Invalid position: { lat|latitude, lng|longitude } required")); } - return RNGeocoder.geocodePosition(position).catch(err => { + const lat = position.lat || position.latitude; + const lng = position.lng || position.longitude; + + const latLng = { lat, lng }; + + return RNGeocoder.geocodePosition(latLng).catch(err => { if (!this.apiKey) { throw err; } - return GoogleApi.geocodePosition(this.apiKey, position); + return GoogleApi.geocodePosition(this.apiKey, latLng); }); }, diff --git a/js/googleApi.js b/js/googleApi.js index 4358de7..f42e3ef 100644 --- a/js/googleApi.js +++ b/js/googleApi.js @@ -59,18 +59,10 @@ function format(raw) { export default { geocodePosition(apiKey, position) { - if (!apiKey || !position || !position.lat || !position.lng) { - return Promise.reject(new Error("invalid apiKey / position")); - } - return this.geocodeRequest(`${googleUrl}?key=${apiKey}&latlng=${position.lat},${position.lng}`); }, geocodeAddress(apiKey, address) { - if (!apiKey || !address) { - return Promise.reject(new Error("invalid apiKey / address")); - } - return this.geocodeRequest(`${googleUrl}?key=${apiKey}&address=${encodeURI(address)}`); },