hero-geo-location
v1.0.2
Published
A CLI tool to get geographical coordinates from an address
Downloads
7
Maintainers
Readme
Hero Geo Location CLI
Hero Geo Location CLI is a simple command-line tool to get geographical coordinates (latitude and longitude) from an address, get an address from coordinates, or search for locations using the Nominatim OpenStreetMap API.
Installation
To install the package globally, run:
npm install -g hero-geo-location
To use the package in your JavaScript project, run:
npm install hero-geo-location
Usage
CLI
To get the geographical coordinates of an address, use the following command:
geo "country,city,street,zipcode"
To get the address from geographical coordinates, use the following command:
geo <lat> <lon>
To search for locations using a query, use the following command:
geo search "query"
JavaScript Module
To get the geographical coordinates of an address in your JavaScript code, use the following code:
const {
getGeoLocation,
getReverseGeoLocation,
searchLocation,
} = require("hero-geo-location");
// Forward geocoding
getGeoLocation("country,city,street,zipcode")
.then((result) => {
console.log(result);
})
.catch((error) => {
console.error(error);
});
// Reverse geocoding
getReverseGeoLocation(lat, lon)
.then((result) => {
console.log(result);
})
.catch((error) => {
console.error(error);
});
// Search locations
searchLocation("query")
.then((results) => {
console.log(results);
})
.catch((error) => {
console.error(error);
});
Examples
CLI Example
Forward Geocoding
geo "USA, New York, 5th Avenue, 10001"
Output:
{
"latitude": "40.7127281",
"longitude": "-74.0060152",
"address": "5th Avenue, New York, NY 10001, USA",
"type": "road",
"name": "5th Avenue, New York, NY 10001, USA",
"country": "United States",
"city": "New York",
"country_code": "us",
"boundingbox": ["40.7127281", "40.7127281", "-74.0060152", "-74.0060152"]
}
Reverse Geocoding
geo -34.44076 -58.70521
Output:
{
"latitude": "-34.44076",
"longitude": "-58.70521",
"address": "Some address in Buenos Aires, Argentina",
"type": "place",
"name": "Some address in Buenos Aires, Argentina",
"country": "Argentina",
"city": "Buenos Aires",
"country_code": "ar",
"boundingbox": ["-34.44076", "-34.44076", "-58.70521", "-58.70521"]
}
Search Location
geo search "rewe Bahnhofstraße berlin"
Output:
[
{
"latitude": "52.4586902",
"longitude": "13.5772772",
"address": "REWE, 33-38, Bahnhofstraße, Dammvorstadt, Köpenick, Treptow-Köpenick, Berlin, 12555, Deutschland",
"type": "supermarket",
"name": "REWE, 33-38, Bahnhofstraße, Dammvorstadt, Köpenick, Treptow-Köpenick, Berlin, 12555, Deutschland",
"country": "Deutschland",
"city": "Berlin",
"country_code": "de",
"boundingbox": ["52.4585902", "52.4587902", "13.5771772", "13.5773772"]
},
{
"latitude": "52.4577394",
"longitude": "13.5789184",
"address": "REWE City, 23-25, Bahnhofstraße, Dammvorstadt, Köpenick, Treptow-Köpenick, Berlin, 12555, Deutschland",
"type": "supermarket",
"name": "REWE City, 23-25, Bahnhofstraße, Dammvorstadt, Köpenick, Treptow-Köpenick, Berlin, 12555, Deutschland",
"country": "Deutschland",
"city": "Berlin",
"country_code": "de",
"boundingbox": ["52.4576394", "52.4578394", "13.5788184", "13.5790184"]
}
]
JavaScript Example
const {
getGeoLocation,
getReverseGeoLocation,
searchLocation,
} = require("hero-geo-location");
// Forward geocoding
getGeoLocation("Germany, Berlin, Unter den Linden, 10117")
.then((result) => {
console.log(result);
})
.catch((error) => {
console.error(error);
});
// Reverse geocoding
getReverseGeoLocation(-34.44076, -58.70521)
.then((result) => {
console.log(result);
})
.catch((error) => {
console.error(error);
});
// Search locations
searchLocation("Unter den Linden 1 Berlin")
.then((results) => {
console.log(results);
})
.catch((error) => {
console.error(error);
});
Author
Milad Davoodabadi
License
ISC