transform a description of a location into geographic coordinates
yarn add react-native-geocodeimport Geocode from "react-native-geocode";
...
Geocode.intialize("GMAPS-API-KEY");
// or with options
Geocode.intialize("GMAPS-API-KEY", {language : "en"});| Accepted props | Type | Description |
|---|---|---|
| apiKey | String | Google Maps Apikey |
| options | Object | Google Geocode Options |
| Accepted parameter | Type |
|---|---|
| Address | String |
| {lat, lng} | Object |
| {latitude, longitude} | Object |
| [latitude, longitude] | Array |
| (latitude, longitude) | Numbers |
// Geocode
Geocode.from("Colosseum").then(json => {
var location = json.results[0].geometry.location;
console.log(location);
}).catch(error => console.warn(error));
// Geocode from location
Geocode.from(41.89, 12.49).then(json => {
var addressComponent = json.results[0].address_components[0];
console.log(addressComponent);
}).catch(error => console.warn(error));
// Geocode from latitude
Geocode.from({
latitude : 41.89,
longitude : 12.49
});
// Geocode from latlng object
Geocode.from({
lat : 41.89,
lng : 12.49
});
// Geocode from array
Geocode.from([41.89, 12.49]);MIT
- Initial release