geocoding services for react native
npm install --save react-native-geocoder
- In the XCode's "Project navigator", right click on Libraries folder under your project ➜
Add Files to <...>
- Go to
node_modules
➜react-native-geocoder
and add theRNGeocoder.xcodeproj
file - Add libRNGeocoder.a to Build Phases -> Link Binary With Libraries
##Installation Android
- In
android/setting.gradle
...
include ':RNGeocoder', ':app'
project(':RNGeocoder').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-geocoder/android')
- In
android/app/build.gradle
...
dependencies {
...
compile project(':RNGeocoder')
}
- register module (in MainActivity.java)
import com.devfd.RNGeocoder.RNGeocoderPackage; // <--- import
public class MainActivity extends Activity implements DefaultHardwareBackBtnHandler {
......
@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new RNGeocoderPackage(), // <------ add this line to your MainActivity class
new MainReactPackage());
}
......
}
var RNGeocoder = require('react-native-geocoder');
// Reverse Geocoding
var NY = {
latitude: 40.7809261,
longitude: -73.9637594
};
RNGeocoder.reverseGeocodeLocation(NY, (err, data) => {
if (err) {
return;
}
console.log(data);
});
// Returned value
[
{
"postalCode":"10024",
"subAdministrativeArea":"New York",
"name":"Central Park",
"locality":"New York",
"subThoroughfare":"1000",
"administrativeArea":"NY",
"position":{
"lat":40.7964708,
"lng":-73.9545696
},
"country":"United States",
"subLocality":"Manhattan",
"thoroughfare":"5th Ave"
}
]
// Address Geocoding
RNGeocoder.geocodeAddress('New York', (err, data) => {
if (err) {
return;
}
console.log(data);
});
// Returned value
[
{
"postalCode":null,
"subAdministrativeArea":"New York",
"name":"New York",
"locality":"New York",
"subThoroughfare":null,
"administrativeArea":"NY",
"position":{
"lat":40.713054,
"lng":-74.007228
},
"country":"United States",
"subLocality":null,
"thoroughfare":null
}
]
RNGeocoder.reverseGeocodeLocation(NY).then((data) => {
...
});
RNGeocoder.geocodeAddress('New York').then((data) => {
...
});
iOS does not allow sending multiple geocoding requests simultaneously.
geocoding may not work on older android devices (4.1) and will not work if Google play services are not available.