fun with maps and php

39
FUN WITH MAPS & PHP Chris Shiflett — @shiflett — shiflett.org

Upload: chris-shiflett

Post on 18-Dec-2014

4.662 views

Category:

Technology


2 download

DESCRIPTION

On a recent road trip around Iceland, my friends (PHP developers Andrei and Helgi) and I decided to make a travel site. We brought our cameras, GPS, and Flips, and we used PHP to: * Aggregate our experience in the form of photos (Flickr), tweets (Twitter), and videos (Vimeo). * Geotag all of these assets, so we'd remember precisely where we were. * Create a map that marks our path each day and plots our photos, tweets, and videos. We made most of this while taking in scenic views and experiencing all Iceland has to offer, and we learned a lot about geotagging, GPSes, time zones, and maps along the way. This talks shows you how to do the same, but you'll have to buy your own flight.

TRANSCRIPT

Page 1: Fun with Maps and PHP

FUN WITH MAPS & PHPChris Shiflett — @shiflett — shiflett.org

Page 2: Fun with Maps and PHP

Who am I? Web aficionado, author, blogger, soccer player, bike rider, beer drinker, music lover, Brooklynite.

Page 3: Fun with Maps and PHP

0. Landice

Dettifoss

Page 4: Fun with Maps and PHP

TRAVELOG

Tag everything– #landice

Blog– every night

Timeline Visualizations– maps?

A!regate and Plot– photos, tweets, videos, etc.

Page 5: Fun with Maps and PHP

1. Research

Sjónarsker

Page 6: Fun with Maps and PHP

EXISTING TOOLS

GPS– Garmin GPS 60CSx

GPSBabel– gpsbabel.org

EveryTrail– everytrail.com

HoudahGeo– houdah.com/houdahGeo/

Page 7: Fun with Maps and PHP

2. Reykjavík

Stóra-Víti

Page 8: Fun with Maps and PHP
Page 9: Fun with Maps and PHP
Page 10: Fun with Maps and PHP
Page 11: Fun with Maps and PHP

3. Photos

Kirkjufell

Page 12: Fun with Maps and PHP

<?xml version="1.0" encoding="UTF-8"?><gpx version="1.0" creator="GPSBabel - http://gpsbabel.org/" xmlns:xsi="http://w3.org/2001/XMLSchema-instance" xmlns="http://topografix.com/GPX/1/0" xsi:schemaLocation="http://topografix.com/GPX/1/0 http://topografix.com/GPX/1/0/gpx.xsd"><time>2009-06-14T23:52:23Z</time><bounds minlat="64.143006038" minlon="-21.955686333" maxlat="64.153455254" maxlon="-21.915427381"/><trk> <name>14-JUN-09 01</name><number>1</number><trkseg><trkpt lat="64.150910676" lon="-21.946594650"> <ele>13.115112</ele> <time>2009-06-14T21:01:25Z</time></trkpt><trkpt lat="64.150785115" lon="-21.945423950"> <ele>13.595825</ele> <time>2009-06-14T21:02:08Z</time></trkpt></trkseg></trk></gpx>

Page 13: Fun with Maps and PHP

$xml = simplexml_load_file('trip.gpx'); foreach($xml->trk as $part) { foreach ($part->trkseg->trkpt as $point) { /* $point['lat'] $point['lon'] $point->time $point->ele */ }}

PARSING GPX

Page 14: Fun with Maps and PHP
Page 15: Fun with Maps and PHP

4. Maps

Bláa lónið

Page 16: Fun with Maps and PHP

HoudahGeo

Garmin GPS 60CSx Nikon D300

Page 17: Fun with Maps and PHP

EVERYTRAIL

Page 18: Fun with Maps and PHP
Page 19: Fun with Maps and PHP

$query = $db->prepare("SELECT lat, lon FROM points WHERE timestamp > '$start' AND timestamp < '$end' ORDER BY timestamp");$query->execute();

$points = array();

while ($row = $query->fetch()) { $points[] = array('lat' => $row['lat'], 'lon' => $row['lon']);}

$trip['points'] = $points;$json = json_encode($trip);file_put_contents("/tmp/landice-$day.json", $json);

Page 20: Fun with Maps and PHP

// FIXME: http://tr.im/selectclosest$sql = "SELECT lat, lon, elevation, ABS(timestamp - :timestamp) as distance FROM points ORDER BY distance LIMIT 1"$select = $this->db->prepare($sql); foreach ($this->photos as $photo) { $id = (string)$photo['id'];  // Get lat and lon from points table. $select->execute(array('timestamp' => $photo['timestamp'])); $row = $select->fetch(); $this->photos[$id]['lat'] = $row['lat']; $this->photos[$id]['lon'] = $row['lon']; $this->photos[$id]['elevation'] = $row['elevation'];}

Page 21: Fun with Maps and PHP

$flickrMethod = 'flickr.photos.getInfo';$apiUrl = "http://api.flickr.com/services/rest/?method={$flickrMethod}&api_key={$this->apiKey}&photo_id={$id}";$xml = simplexml_load_file($apiUrl); $title = (string)$xml->photo->title;$desc = (string)$xml->photo->description;

FLICKR API

Page 22: Fun with Maps and PHP
Page 23: Fun with Maps and PHP

Google Maps OpenStreetMaps

Page 24: Fun with Maps and PHP

5. Challenges

Stykkishólmur

Page 25: Fun with Maps and PHP
Page 26: Fun with Maps and PHP

CLUSTERS

Page 27: Fun with Maps and PHP

20,000 points loaded on a single map is very slow

You don’t need a# points for every view

Mature solutions exist–http://tr.im/polyline

PERFORMANCE

Page 28: Fun with Maps and PHP

6. Storytelling

Reykjavík

Page 29: Fun with Maps and PHP
Page 30: Fun with Maps and PHP
Page 31: Fun with Maps and PHP
Page 32: Fun with Maps and PHP
Page 33: Fun with Maps and PHP

7. Future

Tjörnin

Page 34: Fun with Maps and PHP

TRAILS

GPX Tracking

Page 35: Fun with Maps and PHP

GEOLOCATION API

http://mozi#a.com/en-US/firefox/geolocation/http://dev.w3.org/geo/api/spec-source.html

Page 36: Fun with Maps and PHP

Click here

Page 37: Fun with Maps and PHP
Page 38: Fun with Maps and PHP

Fo#ow me on Twitter– @shiflett

Comment on my blog– shiflett.org

Email me– [email protected]

FEEDBACK?

Page 39: Fun with Maps and PHP

Chris Shiflett — @shiflett — shiflett.org

Thanks for listening!