npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

offline-country-or-place-locator

v2.1.2

Published

Detects country, city or a place by a geometry from a given data set

Downloads

94

Readme

Offline Country or Place Locator

npm license issues

Fork of country-locator by carmi2214

Detects country or place/city by a given geometry.

Installation

npm install offline-country-or-place-locator

Why

Main idea behind this fork is the freedom to have any custom data set as per your requirements. Hence this package doesn't include a data set unlike the original package which included a some 20MB data set of countries. This enables this package to be used in places like react native mobile app and more without the worry of adding extra space.

Where to get the data set

This approach enables the data set to vary depedning on your requirments. For example You can download data sets from:

Custom data set

Or you can create your own custom data set from tools like:

Usage

findPlaceByCoordinate accepts geoJson data set, latitude & longitude, or a point as an array,
and returns the Feature object with the following fields:

  • type: GeoJson type
  • properties: this is where you'll find all the useful information about the country/city/place depending on the data set you input
  • geometry: this is where you'll find the coordinates
import {findPlaceByCoordinate} from "offline-country-or-place-locator";

try{
    const countryInfo = findPlaceByCoordinate(yourCountriesGeoJson, 51.500760, -0.125168);
    
    // assuming your data set has united kingdom and the properties
    // object has "ADMIN" key which stores the country name and
    // the "ISO_A3" key which stores the country code.
    // note these keys could change depending on your data set
    console.log(countryInfo.properties.ADMIN); // United Kingdom
    console.log(countryInfo.properties.ISO_A3); // GBR 
} catch (error){
    console.error(error);
}

You can also call it as a point - an array of [x, y]
PAY ATTENTION - x == longitude and y == latitude

try{
    const countryInfo = findPlaceByCoordinate(yourCountriesGeoJson, [-0.125168, 51.500760]);
    
    console.log(countryInfo.properties.ADMIN); // United Kingdom
    console.log(countryInfo.properties.ISO_A3); // GBR 
} catch (error){
    console.error(error);
}

findPlacesByPolygon accepts a polygon (array of points arrays)
and returns an array of Feature Objects which contains the details of the countries/cities/places (depends on your dataset) that intersect with a given polygon

import {findPlacesByPolygon} from "offline-country-or-place-locator";

try{
    const results = findPlacesByPolygon(yourGeoJson,[
        [-131.484375, 49.781264058178344],
        [-137.548828125, 44.15068115978094],
        [-128.935546875, 26.194876675795218],
        [-96.240234375, 22.755920681486405],
        [-72.50976562499999, 26.43122806450644],
        [-59.501953125, 42.48830197960227],
        [-62.314453125, 48.3416461723746],
        [-76.2890625, 50.3454604086048],
        [-109.77539062499999, 53.173119202640635],
        [-131.484375, 49.781264058178344]
    ]);
    console.log(results);
} catch (error){
    console.error(error);
}

Test

npm run test

License

Offline Country or Place Locator is MIT licensed.