Geotrouvetou – Javascript geo finder


For a recent project I make a library in javascript in order to find the nearest geo point given a coordinate (latitude/longitude).

Geotrouvetou, it is the name of this library, work totally separated from a server or a database. Everything happen on a client side. It’s a really small library, only 3kb when minify, and that does the job.

Geotrouvetou must be initialized with a bench of point. For the sample application, I use more than 26 000 geo localized points that are given by the San Francisco open data web site (https://data.sfgov.org/) related to the crime of the last three months. The library is really fast, here is the output of the sample application.

Welcome to geotrouvetou example
Loading data file
0s 40.114 ms – file loaded
0s 89.722 ms – parsing json
Tree creation
0s 387.768 ms – building tree
26668 points loaded
The app is ready
Enter a location in San Francisco in order to find the nearest crime.
Press Ctrl+Z to close the app
prompt: Latitude: 37.786496
prompt: Longitude: -122.407908
{ latitude: ‘37.7865024401191’,
longitude: ‘-122.407567826112’,
getDirection: [Function],
equals: [Function],
closer: [Function],
data:
[ 26158,
‘E3269308-48B9-466C-83CA-9B00E535DCF4’,
26158,
1364821287,
‘400501’,
1364821287,
‘400501’,
‘{\n}’,
‘130004817’,
‘LARCENY/THEFT’,
‘PETTY THEFT WITH PRIOR’,
‘Wednesday’,
1357113600,
’15:20′,
‘TENDERLOIN’,
‘ARREST, BOOKED’,
‘100 Block of OFARRELL ST’,
‘-122.407567826112’,
‘37.7865024401191’,
[ null, ‘37.7865024401191’, ‘-122.407567826112’, null, false ] ] }
0s 113.445 ms – found

The library can be used in node.js project (npm i geotrouvetou) or directly in a web site application.

As usual, I choose to publish this library under the MIT License. Everything is available in my github.

https://github.com/jbpin/geo-trouvetou

Fell free to fork it, use it, improve it and make pull request.

More to follow.

Enjoy!

Advertisements
Tagged

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: