0.2.0 • Published 4 years ago

react-native-locationiq v0.2.0

Weekly downloads
114
License
MIT
Repository
github
Last release
4 years ago

react-native-locationiq

A geocoding module for React Native to transform geographic coordinates (latitude and longitude) into a description of a location (i.e. street address, town, city, country, etc.) and vice versa.

This module uses LocationIQ Geocoding API and requires an API key for purposes of quota management.

Example

import LocationIQ from 'react-native-locationiq';

// Initialize the module (needs to be done only once)
LocationIQ.init("xxx"); // use a valid API key

LocationIQ.search("Statue of Liberty")
		.then(json => {
			var lat = json[0].lat;
			var lon = json[0].lon;
			console.log(lat, lon);
		})
		.catch(error => console.warn(error));

LocationIQ.reverse(41.89, 12.49)
		.then(json => {
			var address = json.address;
			console.log(adress);
		})
		.catch(error => console.warn(error));

LocationIQ.nearby(41.89, 12.49, 'hospital', 1000)
		.then(json => {
			var address = json.address;
			console.log(adress);
		})
		.catch(error => console.warn(error));

// Works as well :
// ------------

// location object
LocationIQ.reverse({
	latitude : 41.89,
	longitude : 12.49
});

// latlng object
LocationIQ.reverse({
	lat : 41.89,
	lng : 12.49
});

// array
LocationIQ.reverse([41.89, 12.49]);

Error Codes

NameCodeDescription
NOT_INITIATED0Module hasn't been initiated. Call init function, and pass it your app's api key as parameter.
INVALID_PARAMETERS1Parameters are invalid.
FETCHING2Error wile fetching to server. The error's 'origin' property contains the fetch error.
PARSING3Error while parsing server response. The error's 'origin' property contains the response.
SERVER4Error from the server. The error's 'origin' property contains the response's body.

Release Notes

See CHANGELOG.md