4. geotag basics
each location on earth is presented as lat/long pair relative to
180° along the Equator and 90° along the Meridian
Examples
22.278146,114.185259
+22° 16′ N, 114° 11′ E
+22° 16' 41.33", +114° 11' 6.93"
- S/W
+ N/E
6. geotagging the web
as LBS takes off, movement to geotag the web and media follows suite
flickr: ICBM, Geo Tag
geoRSS: great for monitoring
and scientific research
7. geocoding as we don’t speak in coordinates
22.278146,114.185259
202.92.185.47
01558-6-3031
finds lat/long of a point of interest, given partial data
such as an address, an IP or a phone number
10. how address geocoding works
99
96 81 22.278146,114.185259
28 21
step c: interpolate address
use other data like zip code, intersecting streets.etc. to improve accuracy
11. reverse-geocoding does the opposite
22.278146,114.185259
sometimes we need to find non-geotagged points-of-interests
near a location
13. geocoding hong kong addresses
lands department geo db
google maps API
commercial packages
14. geo-searching
most common use-cases:
finding useful data about a location or
finding points-of-interests near a location
need a way to calculate distances between points-of-interests
15. geo-searching: the algorithm
challenge: calculation of distances between places is
less straight forward as the world is not a flat surface
16. geo-searching: the algorithm
visualizing earth as a sphere, mathematicians derive the
great circle between two points and then calculate the
distance between them, using the radius of the sphere
this has been used to help sea navigation routes planning for centuries
17. geo-searching: the algorithm
The haversine formula, given two locations
(lat1,long1), (lat2,long2) and radius of the sphere:
Δlat = lat2− lat1
Δlong = long2− long1
a = sin²(Δlat/2) + cos(lat1).cos(lat2).sin²(Δlong/2)
c = 2.atan2(√a, √(1−a))
d = R.c
other algorithms such as the spherical law of cosines and the Vincenty formulas are widely used as well
18. geo-searching: the algorithm
implementations of the haversine formula, in sql:
SELECT id, ( 3959 * acos( cos( radians(inputLat) ) * cos( radians( lat ) ) *
cos( radians( lng ) - radians(inputLong) ) + sin( radians(inputLat) ) *
sin( radians( lat ) ) ) ) AS distance FROM markers HAVING distance < 10
ORDER BY distance;
* expanded to perform a search for points of interests given a lat/long co-ordinates pair
19. haversine in action
server-side
a. haversine sql lookup
b. draw map with co-
ordinates of points-of-
interests
friendsNearByMap.php
upload location response
20. that was just the beginning
growing usages: location based search marketing
more capable devices: iphone, smartphones, gps cameras