diff --git a/android/build.gradle b/android/build.gradle index 8a174dc..2909971 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -1,14 +1,14 @@ apply plugin: 'com.android.library' android { - compileSdkVersion 25 - buildToolsVersion "25.0.2" + compileSdkVersion 28 + buildToolsVersion "28.0.3" defaultConfig { minSdkVersion 16 - targetSdkVersion 25 - versionCode 1 - versionName "1.0" + targetSdkVersion 27 + versionCode 2 + versionName "1.1" ndk { abiFilters "armeabi-v7a", "x86" } diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..8cdba2d --- /dev/null +++ b/index.d.ts @@ -0,0 +1,5 @@ + +export interface Geocoder { + fallbackToGoogle: (apiKey: string) => void; + enableGoogleGeocoderIOS: () => void; +} diff --git a/js/geocoder.js b/js/geocoder.js index 3a4563e..7b7fe13 100644 --- a/js/geocoder.js +++ b/js/geocoder.js @@ -1,20 +1,32 @@ -import { NativeModules } from 'react-native'; +import { NativeModules, Platform } from 'react-native'; import GoogleApi from './googleApi.js'; const { RNGeocoder } = NativeModules; export default { apiKey: null, + useGoogleOnIOS: false, fallbackToGoogle(key) { this.apiKey = key; }, + enableGoogleGeocoderIOS() { + this.useGoogleOnIOS = Platform.OS === 'ios'; + }, + geocodePosition(position) { if (!position || !position.lat || !position.lng) { return Promise.reject(new Error("invalid position: {lat, lng} required")); } + if (this.useGoogleOnIOS) { + if (!this.apiKey) { + return Promise.reject(new Error("No api key")); + } + return GoogleApi.geocodePosition(this.apiKey, position); + } + return RNGeocoder.geocodePosition(position).catch(err => { if (!this.apiKey) { throw err; } return GoogleApi.geocodePosition(this.apiKey, position); @@ -26,6 +38,13 @@ export default { return Promise.reject(new Error("address is null")); } + if (this.useGoogleOnIOS) { + if (!this.apiKey) { + return Promise.reject(new Error("No api key")); + } + return GoogleApi.geocodeAddress(this.apiKey, position); + } + return RNGeocoder.geocodeAddress(address).catch(err => { if (!this.apiKey) { throw err; } return GoogleApi.geocodeAddress(this.apiKey, address);