@@ -10,19 +10,19 @@ geocoding services for react native
1010```
1111npm install --save react-native-geocoder
1212```
13- ## Installation iOS
13+ ## iOS
1414
15151 . In the XCode's "Project navigator", right click on Libraries folder under your project ➜ ` Add Files to <...> `
16162 . Go to ` node_modules ` ➜ ` react-native-geocoder ` and add ` ios/RNGeocoder.xcodeproj ` file
17173 . Add libRNGeocoder.a to "Build Phases" -> "Link Binary With Libraries"
1818
19- ##Installation Android
19+ ## Android
20201 . In ` android/setting.gradle `
2121
2222``` gradle
2323...
24- include ':RNGeocoder ', ':app'
25- project(':RNGeocoder ').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-geocoder/android')
24+ include ':react-native-geocoder ', ':app'
25+ project(':react-native-geocoder ').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-geocoder/android')
2626```
2727
28283 . In ` android/app/build.gradle `
@@ -31,7 +31,7 @@ project(':RNGeocoder').projectDir = new File(rootProject.projectDir, '../node_mo
3131...
3232dependencies {
3333 ...
34- compile project(':RNGeocoder ')
34+ compile project(':react-native-geocoder ')
3535}
3636```
3737
@@ -58,79 +58,53 @@ public class MainActivity extends Activity implements DefaultHardwareBackBtnHand
5858
5959## Usage
6060```
61- var RNGeocoder = require( 'react-native-geocoder') ;
61+ import Geocoder from 'react-native-geocoder';
6262
63- // Reverse Geocoding
63+ // Position Geocoding
6464var NY = {
65- latitude : 40.7809261,
66- longitude : -73.9637594
65+ lat : 40.7809261,
66+ lng : -73.9637594
6767};
6868
69- RNGeocoder.reverseGeocodeLocation(NY, (err, data) => {
70- if (err) {
71- return;
72- }
73-
74- console.log(data);
75- });
76-
77- // Returned value
78- [
79- {
80- "postalCode":"10024",
81- "subAdministrativeArea":"New York",
82- "name":"Central Park",
83- "locality":"New York",
84- "subThoroughfare":"1000",
85- "administrativeArea":"NY",
86- "position":{
87- "lat":40.7964708,
88- "lng":-73.9545696
89- },
90- "country":"United States",
91- "subLocality":"Manhattan",
92- "thoroughfare":"5th Ave"
93- }
94- ]
69+ Geocoder.geocodePosition(NY).then(res => {
70+ // res is an Array of geocoding object
71+ })
72+ .catch(err => console.log(err))
9573
9674// Address Geocoding
97- RNGeocoder.geocodeAddress('New York', (err, data) => {
98- if (err) {
99- return;
100- }
75+ Geocoder.geocodeAddress('New York').then(res => {
76+ // res is an Array of geocoding object
77+ })
78+ .catch(err => console.log(err))
79+ ```
10180
102- console.log(data);
103- });
104-
105- // Returned value
106- [
107- {
108- "postalCode":null,
109- "subAdministrativeArea":"New York",
110- "name":"New York",
111- "locality":"New York",
112- "subThoroughfare":null,
113- "administrativeArea":"NY",
114- "position":{
115- "lat":40.713054,
116- "lng":-74.007228
117- },
118- "country":"United States",
119- "subLocality":null,
120- "thoroughfare":null
121- }
122- ]
81+ ## With async / await
12382```
83+ const res = await Geocoder.geocodePosition(NY);
84+ ...
12485
125- ## With Promise
86+ const res = await Geocoder.geocodeAddress('London');
87+ ...
12688```
127- RNGeocoder.reverseGeocodeLocation(NY).then((data) => {
128- ...
129- });
13089
131- RNGeocoder.geocodeAddress('New York').then((data) => {
132- ...
133- });
90+ ## Geocoding return format
91+ both iOS and Android will return the following object:
92+
93+ ``` js
94+ {
95+ position: {lat, lng},
96+ formattedAddress: String , // the full address
97+ feature: String | null , // ex Yosemite Park, Eiffel Tower
98+ streetNumber: String | null ,
99+ streetName: String | null ,
100+ postalCode: String | null ,
101+ locality: String | null , // city name
102+ country: String ,
103+ countryCode: String
104+ adminArea: String | null
105+ subAdminArea: String | null ,
106+ subLocality: String | null
107+ }
134108```
135109
136110## Notes
0 commit comments