re:places is a serverless database of 41,000 global cities for your browser

Overview

Re:Places.js

Ok, so still not quite on par with the amazing ...

re:places is a serverless database of 41,000 global cities for your browser. Designed as a light-weight polyfill for ‘cities’ from Algolia's Places API, ahead of the service’s sunset in May 2022. It also runs standalone.

Try it out: Search a city [demo]

Install

  1. Standalone install [demo]
  2. Polyfill Algolia Places API [demo]
  3. Self hosted

Some basic features

  • Faster than you need; a round-trip query averages 20-30ms1
  • Lazy-load the global cities database in under 400kB2 over the wire
  • Filter by country to optimise file size: France weighs in at 20kB2 and Australia comes in under 5kB2
  • Filter results based on a user's IP, proximity to a lat,lng, or the area inside a polygon or bounding box
  • Standalone, or as a zero-config proxy to extend the life of Algolia's Places.js (beyond their API shutdown)
  • Entirely static, nothing required beyond your favourite CDN or storage bucket
  • Entirely free and open source (code is MIT licensed, database is CC BY 4.0)3
  • Contributions celebrated 🎉

Installation & Use

re:places.js is currently intended to be installed from a CDN, with the exception of the polyfill (service worker) script. While modules are in use, they rely on remote imports. This is primarily because the library was coded by hand, without a package manager, and so doesn't have any build steps that might facilitate different versions (UMD, local es6 modules, etc.) Future versions should resolve this shortcoming and provide for a straightforward npm i process. That said, porting the library to run local is trivial.

Standalone install [example]

  1. Import re.places.js into your script (i.e. a module) or document
import replaces from 'https://cdn.jsdelivr.net/npm/[email protected]/re.places.js'
">
<script type="module" async src="https://cdn.jsdelivr.net/npm/[email protected]/re.places.js?global">script>
  1. Search a city:
// this downloads the Australia database (5kb) and runs a search
replaces.search({
  query: 'Cairns',
  countries: ['au'],
})
.then(e => console.log(e));

Advanced setup

// you can provide default options that apply to every search
// refer to the algolia documentation for more info:
// community.algolia.com/places/documentation.html#reconfigurable-options
replaces.init({
  // preload the database
  preload: true,
  // limit it to France and Australia ~= 26Kb download
  countries: ['au', 'fr'],
  // by default we weight results by proximity to an IP location
  // (or at least Algolia do - this library limits it to country)
  // you can turn that off here .. but it's not great for user experience
  aroundLatLngViaIP: false,
  // specify a geo location and distance (in meters), instead of using the IP 
  aroundLatLng: '-16, 145',
  aroundRadius: 3000000, // =300km
  // any results outside this bounding box are excluded
  insideBoundingBox: '-10,154,-29,138',
  // any results outside this polygon are excluded
  insidePolygon: '-10,138,-10,154,-29,154,-34,152,-34,141,-29,138',
})

// any options you provide to a search are merged with your default options
const result = await replaces.search({
  query: 'ca',
  // for this search we want to weight by IP location (even though we turned it off above)
  aroundLatLngViaIP: true,
});

Polyfill Algolia Places API [example]

  1. Download re.places.algolia.js and place the file at the root of your app
  2. Import the library directly after Algolia Places.js, this will install a service worker to intercept any API calls
import 'https://cdn.jsdelivr.net/npm/[email protected]'
// import directly after places.js
import '/re.places.algolia.js'
  1. That's it. Test the your previously set up for places.js

Polyfill with a service worker already in place

The above install will throw an error where a service worker is already installed on a domain. To resolve, import re.places.algolia.sw.js at the top of the existing service worker script. Re.Places only intercepts calls to the Algolia API and does not use any caching strategy. Imported at the top of your script it will work in tandem with any logic already in place.

  1. Edit your main service worker to add the following line to the top of the file
self.importScripts('https://cdn.jsdelivr.net/npm/[email protected]/src/re.places.algolia.sw.js')
// YOUR SERVICE WORKER LOGIC GOES HERE

Self hosted

To self-host the library, you can simply switch out the CDN hosted libraries for local versions. This involves ensuring you have a local copy of each script required for your setup, and replacing any remote urls with your local path. The library was originally built for local use, but later adapted to use a CDN due to the nature of the beast. Future iterations will allow for either approach.

  1. Download the repository or create a local fork
  2. npm install
  3. build the database npm run build-db
  4. search and replace all the remote imports with local paths (we use cdn.jsdelivr.net and all files should be in /, /src and /demo)
  5. test the demo pages npm run demo (you'll need HTTPS on localhost)

Further reading

Check out the source of the demo pages for more detailed explanations of each setup. The scripts themselves are also commented, but there's no guarantees as to coherence. Please feel free to submit an issue or PR to resolve any confusion. Thanks for reading!


re:places © 2022 theprojectsomething | MIT license | Github | Support the project
Hand made with 🖤 in Cairns, Australia

Footnotes

  1. In Cairns, Australia, queries to the Algolia Places API average 250ms (and it feels nice!). With re:places the initial query will run slower due to lazy-loading the database (and an actual network connection being required!) ¯\(ツ)/¯ ... after that you're latency free. See the advanced setup for pre-loading instructions.

  2. The included build script generates a brotli compressed global database weighing in at 396kB, useful for self hosting. CDN compression varies, e.g. ~480kB gzip from JSDelivr / 508kB br from unpkg 2 3

  3. re:places depends on @lucaong/MiniSearch and @rowanwins/point-in-polygon-hao (both MIT / 0 dependencies).
    The database is derived from the basic World Cities Database available from SimpleMaps.com (CC BY 4.0).
    Ideas mixed in from @turfjs and this stackoverflow answer. Cloudflare's 1.1.1.1 supplies location hints.
    Informing everything, of course, is the masterwork that is Algolia Places.
    All amazing efforts. Thank you so much.

You might also like...

List of ~240,000 Persian words

an-array-of-persian-words List of ~240,000 English words. Derived from the Dehkhoda dictionary. Install npm: npm install an-array-of-persian-words Use

Mar 16, 2022

How to create 1,000 videos in 60 seconds

How to create 1,000 videos in 60 seconds

How I built 1,000 personalised videos in 60 seconds In this article, we will show you how to build 1,000 personalized birthday videos for 1,000 differ

Dec 9, 2022

This is a full stack application where you can log all you places where you visited....-

This is a full stack application where you can log all you places where you visited....-

Full Stack Travelling Log 🌍 🎡 ✈️ This is a full stack application where you can log ✈️ your all places 🗽 🗼 🚲 you have visited .... 🗺️ 🗺️ 🗺️ Se

Sep 29, 2022

MERN stack application which serves as an online map journal where users can mark and rate the places they've been to.

MERN stack application which serves as an online map journal where users can mark and rate the places they've been to.

PlaceRate PlaceRate is a MERN stack application which serves as an online map journal where users can mark and rate the places they've been to. You ca

May 17, 2022

Knwl.js is a Javascript library that parses through text for dates, times, phone numbers, emails, places, and more.

Knwl.js Knwl.js is a Javascript library that parses through text for dates, times, phone numbers, emails, places, and more. Project Future The future

Jan 1, 2023

A simple bot for twitch, which has a silly AI in places. The library "cleverbot-free" is used for AI.

A simple bot for twitch, which has a silly AI in places. The library

AITwitchChat A simple bot for twitch, which has a silly AI in places. The library "cleverbot-free" is used for AI. Requiments tmi.js Node.js 16.6.0 or

Dec 7, 2022

Unfurl links into rich cards, as seen in places like Slack and Twitter

eleventy-plugin-unfurl Turn URLs into rich cards. Show a preview image, page title, description and other meta information all inside a neatly present

Dec 16, 2022

Highly opinionated project template for Serverless Framework that follows and applies hexagonal architecture principle to serverless world. Prepared with easy testing in mind.

Highly opinionated project template for Serverless Framework that follows and applies hexagonal architecture principle to serverless world. Prepared with easy testing in mind.

serverless-hexagonal-template Highly opinionated project template for Serverless Framework that applies hexagonal architecture principles to the serve

Dec 26, 2022

Learn Web 2.0 and Web 3.0 Development using Next.js, Typescript, AWS CDK, AWS Serverless, Ethereum and AWS Aurora Serverless

Learn Web 2.0 Cloud and Web 3.0 Development in Baby Steps In this course repo we will learn Web 2.0 cloud development using the latest state of the ar

Jan 3, 2023

A Serverless GraphQL Sample project using Apollo and Serverless Framework with TypeScript and Webpack.

Serverless GraphQL Boilerplate This is a base project with a structure that includes Serverless Framework, Apollo, TypeScript and Webpack. It can be d

Aug 23, 2022

AWS Lambda & Serverless - Developer Guide with Hands-on Labs. Develop thousands line of aws lambda functions interact to aws serverless services with real-world hands-on labs

AWS Lambda & Serverless - Developer Guide with Hands-on Labs. Develop thousands line of aws lambda functions interact to aws serverless services with real-world hands-on labs

AWS Lambda & Serverless - Developer Guide with Hands-on Labs UDEMY COURSE WITH DISCOUNTED - Step by Step Development of this Repository - https://www

Dec 17, 2022

This API can be use to all developers to get location details of Sri Lanka 🇱🇰 including major cities, sub areas, districts and Provinces. ⛳️

This API can be use to all developers to get location details of Sri Lanka  🇱🇰 including major cities, sub areas, districts and Provinces. ⛳️

Location Data API - Sri Lanka Table of Contents Introduction Technologies Implemantations Hosting Use Cases Getting Started Project Setup Contributing

Jun 29, 2022

A node script that lists the cities on Santa's route from santatracker.google.com

Google Santa Route A script that lists the cities on Santa's route from santatracker.google.com based on the JSON containing all Santa's destinations.

Dec 24, 2021

A weather app done with React. Allows you to make a search for the current weather by simply typing "common knowledge" cities and save them to favourites on local storage.

A weather app done with React. Allows you to make a search for the current weather by simply typing

Simpliest Weather React-App A weather app done with React. Allows you to make a search for the current weather by simply typing "common knowledge" cit

Aug 24, 2022

React app that allows users to compare and analyze the cost of living between cities around the world.

✨ LivingApp is a react app that allows users to compare and analyze the cost of living between cities around the world. ✨ Features 🔩 Simple: Bootstra

Feb 5, 2022

Fast API for getting moroccan cities and their districts in json format.

Fast API for getting moroccan cities and their districts in json format.

Fast API for getting moroccan cities and their districts in json format built with Usage The number of requests per user is limited to 100 req/min Lis

Dec 22, 2022

Weather forecast for Turkey's cities.

Weather forecast for Turkey's cities.

Weather App Weather forecast for Turkey's cities. This web app built with using Vite + React. You can preview here Project Details React Day.js for pa

Jan 3, 2023

Weather app created using vanilla JavaScript and APIs. You can search cities worldwide and get current and forecast weather features.

Weather app created using vanilla JavaScript and APIs. You can search cities worldwide and get current and forecast weather features.

Weather App Live Demo About the Project Weather app created using vanilla JavaScript and APIs. You can search cities worldwide and get current and for

Dec 28, 2022
Comments
  • Help using library

    Help using library

    Hi there, I'm looking to add city/state autocomplete search to my app and this looks like the perfect library! Thanks for picking up where Algolia left off.

    I'm having trouble integrating this with my stack. I'm using Rails with esbuild, if it matters.

    If I copy-paste the <script> tag mentioned in the README I get the following error in the console. I'm running Safari v15.2.

    SyntaxError: Unexpected keyword 'export'
    

    If I try to use the dynamic import I get the following error in both Safari and Chrome.

    Error: Dynamic require of "https://cdn.jsdelivr.net/npm/[email protected]/re.places.js" is not supported
    

    Is there some other configuration I am missing to getting it working?

    opened by joemasilotti 5
Owner
technology + strategy + platform + dive monkey @citizensgbr
null
The NASA WorldWind Javascript SDK (WebWW) includes the library and examples for creating geo-browser web applications and for embedding a 3D globe in HTML5 web pages.

Web WorldWind New versions of WorldWind released Web WorldWind 0.10.0 and WorldWind Java 2.2.0 are now available on GitHub. The new version of Web Wor

NASA WorldWind 770 Jan 1, 2023
geotiff.js is a small library to parse TIFF files for visualization or analysis. It is written in pure JavaScript, and is usable in both the browser and node.js applications.

geotiff.js Read (geospatial) metadata and raw array data from a wide variety of different (Geo)TIFF files types. Features Currently available function

geotiff.js 649 Dec 21, 2022
Interactive, thoroughly customizable maps in the browser, powered by vector tiles and WebGL

Mapbox GL JS is a JavaScript library for interactive, customizable vector maps on the web. It takes map styles that conform to the Mapbox Style Specif

Mapbox 9.4k Jan 7, 2023
Utility to warm up your tile server cache

TileMantle A tool to warm up your tile server cache. Give it a URL template, geometry, and list of zoom levels and it will request tiles incrementally

Natural Atlas 34 Sep 12, 2022
Its an app that uses a weather API with access to over 200,000 cities current weather conditons.

Weather App Its an app that uses a weather API with access to over 200,000 cities current weather conditons. Screenshots Links Live Site URL: live sit

Yusuf Lawal 5 Aug 17, 2022
Weather app made using openweather api that supports over 200,000 cities

About This is an open-source weather app built using React.js, and you are welcome to add your unique touch to this project by contributing to the rep

Nikhil Mishra 6 Oct 17, 2022
Grupprojekt för kurserna 'Javascript med Ramverk' och 'Agil Utveckling'

JavaScript-med-Ramverk-Laboration-3 Grupprojektet för kurserna Javascript med Ramverk och Agil Utveckling. Utvecklingsguide För information om hur utv

Svante Jonsson IT-Högskolan 3 May 18, 2022
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
Mekna'7, a subsidiary of the ONCF group, which provides bus services to cities not served by train, needs to set up a computer system by creating a database for managing customer reservations.

Online-bus-ticket-reservation Introduction Hello everyone, this is a project that I have done for assignment. This project is a simple online bus tick

Hala Ziani 5 Oct 25, 2022