Optional: Generating Coordinates

You may need to re-generate the coordinates for the bike stations from time to time, and this page will show you how to do that.

Another reason you may want to re-generate coordinates is so you can use the bike share system in your city with the helmet! It isn't limited to the NYC Citi Bike system.

The below code will parse the wonderful citybik.es api:
Download: file
var request = require('request');
var BIKE_SHARE_URL = 'http://api.citybik.es/citibikenyc.json';
request(BIKE_SHARE_URL, function (error, response, body) {
  if (!error && response.statusCode == 200) {
    var comma = ",";
    var locations = JSON.parse(body);
    locations.forEach(function(l, i) {
      if (i === locations.length-1)
        comma = "";

      console.log("  {" + (l.lat / 1000000).toFixed(6) + ", " + (l.lng / 1000000).toFixed(6) + "}" + comma);
    });

    console.log(locations.length);
  }
});
Let's not get too far ahead of ourselves though. First, we need to install the dependencies to run that code.

To start with, you'll need node.js. It's a really easy install. Navigate to http://nodejs.org, and follow the installation instructions for your operating system (Windows, Linux, and OS X are supported).

Next, create a folder somewhere (mine is titled 'cityparser'). Then, create a file in that folder titled parser.js and copy and paste the above snippet of code into that file, and save it.

Now, open your favorite command line utility (Terminal.app, cmd.exe, etc) and navigate into the 'cityparser' folder.

Now, we need to install the one dependency that is required for the parser to run. Execute the following from within the cityparser folder:
Download: file
npm install request
Now that you have request installed, you can (finally!) run the parser to generate the locations for your particular city bike share program.

Execute the following command to run the parser:
Download: file
node parser.js
Great! It should have output a bunch of coordinates with a count at the end of it.

For example, these are the last few of my output:
Download: file
  {40.715348, -73.960241},
  {40.741472, -73.983209},
  {40.736502, -73.978094},
  {40.744449, -73.983035},
  {40.702550, -73.989402},
  {40.698920, -73.973329},
  {40.716887, -73.963198},
  {40.734160, -73.980242},
  {40.725500, -74.004451},
  {40.705311, -73.971000},
  {40.765909, -73.976341}
311
If your output is similar to the above, you'll now want to choose the correct BIKE_SHARE_URL for your city (NYC pre-loaded).

Open the citybik.es api page, and scroll down to the section titled "System" and "JSON". Choose your location from the dropdown, and then replace it in the parser.js file variable "BIKE_SHARE_URL" and re-run the program.

Ok, now to set up your sketch. The last number in the results is the count of locations in that bike share. Take that number and place it in the sketch for the size of the array:
Download: file
#define LAT_LON_SIZE 311
Then, copy and paste all of the locations (not the number), and replace the existing locations in the Bike Helmet Sketch. It should look something like this:
Download: file
float lat_lon[LAT_LON_SIZE][2] PROGMEM = {
  {40.767272, -73.993928},
  {40.719115, -74.006666},
  {40.711174, -74.000165},
  {40.683826, -73.976323},
  {40.702550, -73.989402},
  {40.698920, -73.973329},
  {40.716887, -73.963198},
  {40.734160, -73.980242},
  {40.725500, -74.004451},
  {40.705311, -73.971000},
  {40.765909, -73.976341}
};
Now, compile your sketch, upload it, and start biking!
This guide was first published on Jun 19, 2013. It was last updated on Jun 19, 2013. This page (Optional: Generating Coordinates) was last updated on Apr 22, 2019.