Skip to content

Instantly share code, notes, and snippets.

@philsturgeon
Last active December 10, 2015 12:08
Show Gist options
  • Save philsturgeon/4431748 to your computer and use it in GitHub Desktop.
Save philsturgeon/4431748 to your computer and use it in GitHub Desktop.
Create a GPX file of Foursquare checkins

Grab your access token, update run.rb, then run this command:

Usage

$ ruby run.rb

<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<gpx xmlns="http://www.topografix.com/GPX/1/1" xmlns:gpxx="http://www.garmin.com/xmlschemas/GpxExtensions/v3" xmlns:gpxtpx="http://www.garmin.com/xmlschemas/TrackPointExtension/v1" creator="Oregon 400t" version="1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd http://www.garmin.com/xmlschemas/GpxExtensions/v3 http://www.garmin.com/xmlschemas/GpxExtensionsv3.xsd http://www.garmin.com/xmlschemas/TrackPointExtension/v1 http://www.garmin.com/xmlschemas/TrackPointExtensionv1.xsd">

  <metadata>
    <link href="http://www.foursquare.com">
      <text>Foursquare Checkins</text>
    </link>
    <time>2013-01-01T22:00:37-05:00</time>
  </metadata>

  <trk>
    <name>Four Points by Sheraton Mississauga Meadowvale</name>
    <trkseg>
      <trkpt lat="43.60141615721874" lon="-79.7555046835973">
        <time>2012-11-01T17:24:18-04:00</time>
      </trkpt>
    </trkseg>
  </trk>

  <trk>
    <name>InterContinental Hotel</name>
    <trkseg>
      <trkpt lat="40.75850533742767" lon="-73.98914337158203">
        <time>2012-10-28T18:09:30-04:00</time>
      </trkpt>
    </trkseg>
  </trk>
</gpx>

To save this just pipe the output to a file:

$ ruby run.rb > foursquare.gpx

That will save the XML content in the file, or you can miss out the second half to get a preview.

Fog of World Imports

If like me you are a massive Fog of World geek then just set up Dropbox imports on the iPhone application and share like this:

$ ruby run.rb > ~/Dropbox/Apps/Fog\ of\ World/GPX/foursquare.gpx

source 'https://rubygems.org'
gem "json"
gem "typhoeus"
gem "quimby"
require 'quimby'
require 'time'
# Easiest way to get a token is from https://developer.foursquare.com/docs/explore
token = "YOUR_ACCESS_TOKEN"
foursquare = Foursquare::Base.new(token)
user = foursquare.users.find('self')
puts '<?xml version="1.0" encoding="UTF-8" standalone="no" ?>'
puts '<gpx xmlns="http://www.topografix.com/GPX/1/1" xmlns:gpxx="http://www.garmin.com/xmlschemas/GpxExtensions/v3" xmlns:gpxtpx="http://www.garmin.com/xmlschemas/TrackPointExtension/v1" creator="Oregon 400t" version="1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd http://www.garmin.com/xmlschemas/GpxExtensions/v3 http://www.garmin.com/xmlschemas/GpxExtensionsv3.xsd http://www.garmin.com/xmlschemas/TrackPointExtension/v1 http://www.garmin.com/xmlschemas/TrackPointExtensionv1.xsd">'
puts "
<metadata>
<link href=\"http://www.foursquare.com\">
<text>Foursquare Checkins</text>
</link>
<time>#{Time.now.iso8601}</time>
</metadata>"
user.all_checkins.each do |checkin|
puts "
<trk>
<name>#{checkin.venue.name}</name>
<trkseg>
<trkpt lat=\"#{checkin.venue.location.lat}\" lon=\"#{checkin.venue.location.lng}\">
<time>#{checkin.created_at.to_time.iso8601}</time>
</trkpt>
</trkseg>
</trk>"
end
puts '
</gpx>'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment