• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Geo search introduction

Geo search introduction



Another presentation prepared for team sharing. An idea that have great potentials that is geo search.

Another presentation prepared for team sharing. An idea that have great potentials that is geo search.



Total Views
Views on SlideShare
Embed Views



2 Embeds 9

http://www.corgitoergosum.net 6
http://www.slideshare.net 3



Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
Post Comment
Edit your comment

    Geo search introduction Geo search introduction Presentation Transcript

    • geo
search the
    • LBS is ubiquitous but remains somehow a mystery let’s visit some of the basics
    • query in geo-search: geotags
    • 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
    • geotagging photos gps trackers embed lat/long coordinates in the EXIF section of a photo
    • 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
    • geocoding as we don’t speak in coordinates 22.278146,114.185259 01558-6-3031 finds lat/long of a point of interest, given partial data such as an address, an IP or a phone number
    • how address geocoding works step a: parse or rewrite the address
    • how address geocoding works step b: locate corresponding map segment
    • 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
    • reverse-geocoding does the opposite 22.278146,114.185259 sometimes we need to find non-geotagged points-of-interests near a location
    • reverse-geocoding
    • geocoding hong kong addresses lands department geo db google maps API commercial packages
    • 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
    • geo-searching: the algorithm challenge: calculation of distances between places is less straight forward as the world is not a flat surface
    • 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
    • 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
    • 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
    • haversine in action server-side a. haversine sql lookup b. draw map with co- ordinates of points-of- interests friendsNearByMap.php upload location response
    • that was just the beginning growing usages: location based search marketing more capable devices: iphone, smartphones, gps cameras
    • references http://en.wikipedia.org/wiki/Geotagging http://www.uncorneredmarket.com/2008/02/geotagging-your-photos-importing-embedding/ http://www.codeproject.com/KB/scrapbook/ask_GoogleMap_Geocoder.aspx http://computer.howstuffworks.com/mapquest2.htm http://en.wikipedia.org/wiki/Great-circle_distance http://www.phpbites.com/2008/05/30/getting-to-the-point#more37 http://www.movable-type.co.uk/scripts/gis-faq-5.1.html http://en.wikipedia.org/wiki/Haversine_formula http://www.movable-type.co.uk/scripts/latlong.html http://code.google.com/apis/maps/articles/phpsqlsearch.html#findnearsql http://www.developer.com/lang/jscript/article.php/3615681 http://mathworld.wolfram.com/GreatCircle.html http://www.scribd.com/doc/2669666/Geo-Distance-Search-with-MySQL-Presentation
    • friendsNearByMap.php <?php $mapHTML = <<<END_HTML <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"/> <script src="http://maps.google.com/maps? file=api&amp;v=2&amp;key=ABQIAAAAIyNua8PP_PzqZ7hTFF3NThR_fjc6V75Vk4buUDX2vYNSgRJ_LxQdsrhokMtHy8yClRqUkWyUUQy Ajg" type="text/javascript"></script> <script type="text/javascript"> function load() { if (GBrowserIsCompatible()) { var map = new GMap2(document.getElementById("map")); map.setCenter(new GLatLng($where), 16); map.addControl(new GSmallMapControl()); var tinyIcon = new GIcon(); tinyIcon.image = "http://labs.google.com/ridefinder/images/mm_20_red.png"; ... map.addOverlay(marker); END_HTML;
    • friendsNearByMap.php (2) <?php // Get parameters from URL $centerLong = $_REQUEST['long']; $centerLat = $_REQUEST['lat']; // 10 miles $radius = 10; $query = sprintf("SELECT user_name, now, latitude, longitude, ( 3959 * acos( cos( radians('%s') ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians('%s') ) + sin( radians('%s') ) * sin( radians( latitude ) ) ) ) AS distance FROM plan HAVING distance < '%s' ORDER BY distance LIMIT 0 , 20", mysql_real_escape_string($centerLat), mysql_real_escape_string($centerLong), mysql_real_escape_string($centerLat), mysql_real_escape_string($radius)); $result = mysql_query($query);
    • friendsNearByMap.php (3) // Iterate through the rows, print out details$i = 0; while ($row = @mysql_fetch_assoc($result)){ $nearbyUserName = $row['user_name']; $nearbyNow = $row['now']; $nearbyLatitude = $row['latitude']; $nearbyLongitude = $row['longitude']; $mapHTML = $mapHTML."n var latlng$i = new GLatLng($nearbyLatitude,$nearbyLongitude);"; $mapHTML = $mapHTML."n var marker$i = createMarker(latlng$i, '$nearbyUserName', '$nearbyNow');"; $mapHTML = $mapHTML."n map.addOverlay(marker$i);"; $i++; } ?> function createMarker(point, name, now) { var marker = new GMarker(point); var html = '<b>' + name + '</b> is now:<br/>' + now; GEvent.addListener(marker, 'click', function() { marker.openInfoWindowHtml(html); }); return marker; } </script></head> <body onload="load()" onunload="GUnload()"> <div id="map" style="width: 300px; height: 390px"></div> </body> </html>