This repository was archived by the owner on Sep 4, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 180
Expand file tree
/
Copy pathgeocoder.js
More file actions
56 lines (45 loc) · 1.55 KB
/
geocoder.js
File metadata and controls
56 lines (45 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { NativeModules } from 'react-native';
import GoogleApi from './googleApi.js';
const { RNGeocoder } = NativeModules;
export default {
apiKey: null,
fallbackToGoogle(key) {
this.apiKey = key;
},
geocodePositionWithLanguage(position, language){
if (!position || !position.lat || !position.lng) {
return Promise.reject(new Error("invalid position: {lat, lng} required"));
}
return RNGeocoder.geocodePositionWithLanguage(position, language).catch(err => {
if (!this.apiKey) { throw err; }
return GoogleApi.geocodePosition(this.apiKey, position);
});
}
geocodeAddressWithLanguage(address, language) {
if (!address) {
return Promise.reject(new Error("address is null"));
}
return RNGeocoder.geocodeAddressWithLanguage(address, language).catch(err => {
if (!this.apiKey) { throw err; }
return GoogleApi.geocodeAddress(this.apiKey, address);
});
},
geocodePosition(position) {
if (!position || !position.lat || !position.lng) {
return Promise.reject(new Error("invalid position: {lat, lng} required"));
}
return RNGeocoder.geocodePosition(position).catch(err => {
if (!this.apiKey) { throw err; }
return GoogleApi.geocodePosition(this.apiKey, position);
});
},
geocodeAddress(address) {
if (!address) {
return Promise.reject(new Error("address is null"));
}
return RNGeocoder.geocodeAddress(address).catch(err => {
if (!this.apiKey) { throw err; }
return GoogleApi.geocodeAddress(this.apiKey, address);
});
},
}