Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

city

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

city

The City API returns the city from a latitude and longitude using spatial mapping and data anlysis.

  • 1.0.4
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
3
decreased by-40%
Maintainers
1
Weekly downloads
 
Created
Source

City

The City API gets a city or closest city from a latitude and longitude.

It uses an algorithim that utilises spatial mapping and sophisticated data analysis to give you a blazing fast and accurate response from over 150,000 cities from every country across the globe.

This package requires an API key which can be generated Here.

logo

Installation

npm i city --save

Usage

const city = require( 'city' )

//Using Promises
city.get( latitude, longitude, size, apiKey )
    .then( location => {
      console.log( location )
    })
    .catch( e => console.log( e ))
    
//Async await
const location = await city.get( latitude, longitude, size, apiKey )

City Sizes

SizeDescription
NULLThis will search through every city of every size
0Major Cities, 1m+ population
1Big Cities, 250k - 1m population
2Medium Cities, 10k - 250k population
3Small cities, under 10k population

Demos

city.get( 35.4526317, 139.4546863, 0, apiKey )
//Response
{
    city: 'Yokohama'.
    country: 'JP',
    population: 3574443,
    distance: 17.823109463333083
}

city.get( 42.34133262, -83.05576000, 1, apiKey )
//Response
{
    city: 'Detroit'.
    country: 'US',
    population: 677116,
    distance: 1.3745663787473823
}

Response

PropertyDescription
cityThe city name.
countryThe 2 letter country code which the city is located.
populationThe last updated population of that city.
distanceThe distance between the user and city center in km.

Errors

StatusErrorDescription
422API KEY NOT FOUNDYou need to pass your API key as a parameter. You can get one Here.
422INVALID API KEYYour key is invalid or badly formatted.
422INVALID SIZEYour size parameter is invalid.
402NO CREDITS REMAININGYou need to purchase more credits for your key. You can do that Here.
422INVALID COORDINATESMissing or invalid latitude/ longitude.

Documentation

This is a brand new API launced in February 2021. Full Documentation will be here soon.

Click Here to see the full documentation

Use cases

  • Location based social media
  • Dating services
  • Profiles
  • Location based games
  • Environmental evaluation
  • Map and directions services

Keywords

FAQs

Package last updated on 06 Feb 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc