das webwird mobilStephan Schmidt, 1&1 Internet AGInternational PHP Conference 2012Hotel Maritim proArte, Berlin
beiArbeit
Sport
undSpiel
ich suche cup-cakes in meinernähe.
schritt eins:wo bin ich?
geolocation vordem jahr 2008:
91.22.203.142
where the heck isoberderdingen?
google weißziemlich genauwo* ich bin.* und zwar nicht in oberderdingen.
geolocation imjahr 2012:
geographische länge 48.96977,8.613199geographische breite
breitengradelängengrade
woher weißmein browserdas?
geolocationapi
+
agie!    etw   asMund
die Magie ist ausjavascript nutz-bar.
if (navigator.geolocation) {   navigator.geolocation.getCurrentPosition (      function(position) {         // location re...
Geoposition  coords : Coordinates    accuracy : 65 // meter    altitude : null    altitudeAccuracy : null    heading : nul...
PositionError  code : 1  constructor : PositionErrorConstructor    PERMISSION_DENIED : 1    POSITION_UNAVAILABLE : 2    TI...
navigator.geolocation.getCurrentPosition(  function(position) {...},  function(error) {...},  {     enableHighAccuracy : t...
navigator.geolocation.watchPosition (   function(pos) {      // position changed   },   function(error) {      // error ha...
9.0+   3.5+   5.0+   5.0+   10.6+       3.0+          2.0+
where the heck is52.51832,13.387145?
var latlon = new google.maps.LatLng(pos.coords.latitude,                                    pos.coords.longitude);var opti...
menschenwollen lieberadressen.
http://maps.google.com/maps/api/service/output?latlng=lat,lon&sensor=false
geocodehttp://maps.google.com/maps/api/service/output?latlng=lat,lon&sensor=false
xml | jsonhttp://maps.google.com/maps/api/service/output?latlng=lat,lon&sensor=false
positionhttp://maps.google.com/maps/api/service/output?latlng=lat,lon&sensor=false
genug javascript,jetzt kommt derelefant.
public function geocodeReverse($lat, $lon) { $url = sprintf(http://maps.google.com/maps/api/ .        geocode/json?latlng=...
"results" : [    {       "address_components" : [...],       "formatted_address" : "Mittelstraße 23, 10117 Berlin, Germany...
try { $geocoder = new Geocoder(); $results = $geocoder->geocodeReverse($lat, $lon);  echo "<ul>";  foreach ($results as $r...
•Mittelstraße 23, 10117 Berlin, Germany (street_address)•10117 Berlin, Germany (postal_code)•Mitte, Berlin, Germany (sublo...
Laut Google:      Laut Hotel:Mittelstraße 23   Friedrichstraße 15110117 Berlin      10117 BerlinGermany           Germany
schritt zwei:wo sind diecupcakes?
https:/maps.googleapis.com/maps/api/place/method/output?parameters&key=[key]
sicherheithttps:/maps.googleapis.com/maps/api/place/method/output?parameters&key=[key]
search | detailhttps:/maps.googleapis.com/maps/api/place/method/output?parameters&key=[key]
xml | jsonhttps:/maps.googleapis.com/maps/api/place/method/output?parameters&key=[key]
location  radius  sensorkeyword   name   types  rankbylanguage
https://maps.googleapis.com/maps/api/place/search/json?location=52.5185,13.3885&types=food&radius=25000&key=...&sensor=fal...
{    "html_attributions" : [       "Listings by ...."    ],    "results" : [       {         "geometry" : {            "lo...
$config = parse_ini_file(google-places.ini);$long = $_GET[long];$lat = $_GET[lat];$searchUrl = sprintf("https://maps.....sea...
if ($response->status !== OK) {    printf(<p>Es ist ein Fehler aufgetreten: %s</p>,    $response->status);} else {    prin...
schritt zwei ½:wie weit ist esnoch?
ca    b
die erde ist                   eine kugel*.* eigentlich ein ellipsoid.
dist = 6378.388 *  acos(   sin(lat1) * sin(lat2)    +   cos(lat1) * cos(lat2)    *   cos(lon2 - lon1))         http://www....
function calcDistance($lat1, $lon1, $lat2, $lon2) {  $lat1 = deg2rad($lat1);  $lon1 = deg2rad($lon1);  $lat2 = deg2rad($la...
geht das auchohne google?
https://api.foursquare.com/v2/venues/search?intent=browse&ll=lat,lon&radius=10000&limit=15&query=Cupcake&client_id=[id]&cl...
sicherheithttps://api.foursquare.com/v2/venues/search?intent=browse&ll=lat,lon&radius=10000&limit=15&query=Cupcake&client_...
versionierunghttps://api.foursquare.com/v2/venues/search?intent=browse&ll=lat,lon&radius=10000&limit=15&query=Cupcake&clie...
positionhttps://api.foursquare.com/v2/venues/search?intent=browse&ll=lat,lon&radius=10000&limit=15&query=Cupcake&client_id...
$config = parse_ini_file(config/foursquare-config.ini);$searchUrl = sprintf(https://....../venues/search?.          intent=bro...
"categories": [   {      "id" : "4bf58dd8d48988d1bc941735",      "name" : "Cupcake Shop",      "pluralName" : "Cupcake Sho...
personalisierteempfehlungen
wie unterstütztdas mein business?
Beware of theDark Side, Luke.
http://www.cultofmac.com/157641/this-creepy-app-isnt-just-stalking-women-     without-their-knowledge-its-a-wake-up-call-a...
vielen dank.Stephan SchmidtHead of Web Sales Development1&1 Internet AGschst@php.netwww.schst.nettwitter.com/schst
Das Web Wird Mobil - Geolocation und Location Based Services
Das Web Wird Mobil - Geolocation und Location Based Services
Das Web Wird Mobil - Geolocation und Location Based Services
Das Web Wird Mobil - Geolocation und Location Based Services
Das Web Wird Mobil - Geolocation und Location Based Services
Das Web Wird Mobil - Geolocation und Location Based Services
Das Web Wird Mobil - Geolocation und Location Based Services
Das Web Wird Mobil - Geolocation und Location Based Services
Das Web Wird Mobil - Geolocation und Location Based Services
Das Web Wird Mobil - Geolocation und Location Based Services
Das Web Wird Mobil - Geolocation und Location Based Services
Das Web Wird Mobil - Geolocation und Location Based Services
Das Web Wird Mobil - Geolocation und Location Based Services
Das Web Wird Mobil - Geolocation und Location Based Services
Das Web Wird Mobil - Geolocation und Location Based Services
Das Web Wird Mobil - Geolocation und Location Based Services
Das Web Wird Mobil - Geolocation und Location Based Services
Das Web Wird Mobil - Geolocation und Location Based Services
Das Web Wird Mobil - Geolocation und Location Based Services
Upcoming SlideShare
Loading in...5
×

Das Web Wird Mobil - Geolocation und Location Based Services

2,444

Published on

Vortrag auf der International PHP Conference 2012 Spring Edition zu Geolocation im Browser und Location Based Services wie Google Places und Foursquare

Published in: Technology, Travel
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,444
On Slideshare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
12
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Das Web Wird Mobil - Geolocation und Location Based Services

  1. 1. das webwird mobilStephan Schmidt, 1&1 Internet AGInternational PHP Conference 2012Hotel Maritim proArte, Berlin
  2. 2. beiArbeit
  3. 3. Sport
  4. 4. undSpiel
  5. 5. ich suche cup-cakes in meinernähe.
  6. 6. schritt eins:wo bin ich?
  7. 7. geolocation vordem jahr 2008:
  8. 8. 91.22.203.142
  9. 9. where the heck isoberderdingen?
  10. 10. google weißziemlich genauwo* ich bin.* und zwar nicht in oberderdingen.
  11. 11. geolocation imjahr 2012:
  12. 12. geographische länge 48.96977,8.613199geographische breite
  13. 13. breitengradelängengrade
  14. 14. woher weißmein browserdas?
  15. 15. geolocationapi
  16. 16. +
  17. 17. agie! etw asMund
  18. 18. die Magie ist ausjavascript nutz-bar.
  19. 19. if (navigator.geolocation) { navigator.geolocation.getCurrentPosition ( function(position) { // location retrieved }, function(error) { // error happened } );}
  20. 20. Geoposition coords : Coordinates accuracy : 65 // meter altitude : null altitudeAccuracy : null heading : null latitude : 52.518328398571434 longitude : 13.387145829999998 speed : null
  21. 21. PositionError code : 1 constructor : PositionErrorConstructor PERMISSION_DENIED : 1 POSITION_UNAVAILABLE : 2 TIMEOUT : 3 message: "User denied Geolocation"
  22. 22. navigator.geolocation.getCurrentPosition( function(position) {...}, function(error) {...}, { enableHighAccuracy : true, timeout : 5000, // milliseconds maximumAge : 1000 * 60 // milliseconds } );}
  23. 23. navigator.geolocation.watchPosition ( function(pos) { // position changed }, function(error) { // error happened })
  24. 24. 9.0+ 3.5+ 5.0+ 5.0+ 10.6+ 3.0+ 2.0+
  25. 25. where the heck is52.51832,13.387145?
  26. 26. var latlon = new google.maps.LatLng(pos.coords.latitude, pos.coords.longitude);var options = { zoom: 15, center: latlon, mapTypeId: google.maps.MapTypeId.ROADMAP};var map = new google.maps.Map($("#map"), options);var marker = new google.maps.Marker({ position: latlon, map: map, title:"Sie sind hier!"});
  27. 27. menschenwollen lieberadressen.
  28. 28. http://maps.google.com/maps/api/service/output?latlng=lat,lon&sensor=false
  29. 29. geocodehttp://maps.google.com/maps/api/service/output?latlng=lat,lon&sensor=false
  30. 30. xml | jsonhttp://maps.google.com/maps/api/service/output?latlng=lat,lon&sensor=false
  31. 31. positionhttp://maps.google.com/maps/api/service/output?latlng=lat,lon&sensor=false
  32. 32. genug javascript,jetzt kommt derelefant.
  33. 33. public function geocodeReverse($lat, $lon) { $url = sprintf(http://maps.google.com/maps/api/ . geocode/json?latlng=%s,%s&sensor=false, $lat, $lon); $json = file_get_contents($url); $response = json_decode($json); if ($response->status === OK) { return $response->results; } else { throw new Exception($response->status); } }
  34. 34. "results" : [ { "address_components" : [...], "formatted_address" : "Mittelstraße 23, 10117 Berlin, Germany", "geometry" : { "location" : { "lat" : 52.51820, "lng" : 13.387170 }, "location_type" : "ROOFTOP", "viewport" : { "northeast" : {...}, "southwest" : {...} } }, "types" : [ "street_address" ] }, { "address_components" : [ ... ], "formatted_address" : "10117 Berlin, Germany", "geometry" : { "bounds" : {...} }, "location" : {...}, "location_type" : "APPROXIMATE", "viewport" : {...}, "types" : [ "postal_code" ] }, ...]
  35. 35. try { $geocoder = new Geocoder(); $results = $geocoder->geocodeReverse($lat, $lon); echo "<ul>"; foreach ($results as $result) { printf("<li>%s (%s)</li>", $result->formatted_address, implode(, , $result->types)); } echo "</ul>";} catch (Exception $e) { echo "Geocodierung ist fehlgeschlagen: " . $e->getMessage();}
  36. 36. •Mittelstraße 23, 10117 Berlin, Germany (street_address)•10117 Berlin, Germany (postal_code)•Mitte, Berlin, Germany (sublocality, political)•Berlin, Germany (locality, political)•Berlin, Germany (administrative_area_level_1, political)•Germany (country, political)
  37. 37. Laut Google: Laut Hotel:Mittelstraße 23 Friedrichstraße 15110117 Berlin 10117 BerlinGermany Germany
  38. 38. schritt zwei:wo sind diecupcakes?
  39. 39. https:/maps.googleapis.com/maps/api/place/method/output?parameters&key=[key]
  40. 40. sicherheithttps:/maps.googleapis.com/maps/api/place/method/output?parameters&key=[key]
  41. 41. search | detailhttps:/maps.googleapis.com/maps/api/place/method/output?parameters&key=[key]
  42. 42. xml | jsonhttps:/maps.googleapis.com/maps/api/place/method/output?parameters&key=[key]
  43. 43. location radius sensorkeyword name types rankbylanguage
  44. 44. https://maps.googleapis.com/maps/api/place/search/json?location=52.5185,13.3885&types=food&radius=25000&key=...&sensor=false&name=cupcake
  45. 45. { "html_attributions" : [ "Listings by ...." ], "results" : [ { "geometry" : { "location" : { "lat" : 52.5107460, "lng" : 13.4577320 } }, "icon" : "http://maps.gstatic.com/ma...s/restaurant-71.png", "id" : "b9a03f408df6ade6021a150d3bf5ae04f24853db", "name" : "Cupcake", "rating" : 4.10, "reference" : "CnRl...R7TAHjPh_H2Mw", "types" : [ "store", "cafe", "restaurant", "food"], "vicinity" : "Krossener Straße 12, Berlin" }, ....], "status" : "OK"}
  46. 46. $config = parse_ini_file(google-places.ini);$long = $_GET[long];$lat = $_GET[lat];$searchUrl = sprintf("https://maps.....search/json". "?location=%s,%s&types=food&radius=25000&“. "key=%s&sensor=false", $lat, $long, $config[googlekey]);if (isset($_GET[search])) { $searchUrl = $searchUrl . "&name=" . $_GET[search];}$jsonResponse = file_get_contents($searchUrl);$response = json_decode($jsonResponse);
  47. 47. if ($response->status !== OK) { printf(<p>Es ist ein Fehler aufgetreten: %s</p>, $response->status);} else { print <ul style="float: left; margin-right: 25px;">; foreach ($response->results as $entry) { $rating = isset($entry->rating) ? $entry->rating : 0; print <li>; printf(<a href="google-detail.php?reference=%s">%s</a>. <div class="rating_bar" title="Bewertung: %s"> . <div style="width:%d%%"></div></div>, $entry->reference, $entry->name, $rating, $rating/5*100); print </li>; } print </ul>;}
  48. 48. schritt zwei ½:wie weit ist esnoch?
  49. 49. ca b
  50. 50. die erde ist eine kugel*.* eigentlich ein ellipsoid.
  51. 51. dist = 6378.388 * acos( sin(lat1) * sin(lat2) + cos(lat1) * cos(lat2) * cos(lon2 - lon1)) http://www.kompf.de/gps/distcalc.html
  52. 52. function calcDistance($lat1, $lon1, $lat2, $lon2) { $lat1 = deg2rad($lat1); $lon1 = deg2rad($lon1); $lat2 = deg2rad($lat2); $lon2 = deg2rad($lon2); return 6378.388 * acos(sin($lat1) * sin($lat2) + cos($lat1) * cos($lat2) * cos($lon2 - $lon1));}
  53. 53. geht das auchohne google?
  54. 54. https://api.foursquare.com/v2/venues/search?intent=browse&ll=lat,lon&radius=10000&limit=15&query=Cupcake&client_id=[id]&client_secret=[secret]&v=20111113
  55. 55. sicherheithttps://api.foursquare.com/v2/venues/search?intent=browse&ll=lat,lon&radius=10000&limit=15&query=Cupcake&client_id=[id]&client_secret=[secret]&v=20111113
  56. 56. versionierunghttps://api.foursquare.com/v2/venues/search?intent=browse&ll=lat,lon&radius=10000&limit=15&query=Cupcake&client_id=[id]&client_secret=[secret]&v=20111113
  57. 57. positionhttps://api.foursquare.com/v2/venues/search?intent=browse&ll=lat,lon&radius=10000&limit=15&query=Cupcake&client_id=[id]&client_secret=[secret]&v=20111113
  58. 58. $config = parse_ini_file(config/foursquare-config.ini);$searchUrl = sprintf(https://....../venues/search?. intent=browse&ll=%s,%s&radius=10000&limit=15. &query=Cupcake&client_id=%s&client_secret=%s. &v=20111113, $lat, $long, $config[clientId], $config[clientSecret]);$jsonResponse = file_get_contents($searchUrl);$response = json_decode($jsonResponse);foreach ($response->response->venues as $venue) { printf("<li>%s (%0.2f km)</li>", $venue->name, $venue->location->distance/1000);}
  59. 59. "categories": [ { "id" : "4bf58dd8d48988d1bc941735", "name" : "Cupcake Shop", "pluralName" : "Cupcake Shops", "shortName" : "Cupcakes", "icon" : { "prefix" : "https://.../categories/food/cupcakes_", "sizes" : [32,44,64,88,256], "name" : ".png" }, "primary" : true } ]
  60. 60. personalisierteempfehlungen
  61. 61. wie unterstütztdas mein business?
  62. 62. Beware of theDark Side, Luke.
  63. 63. http://www.cultofmac.com/157641/this-creepy-app-isnt-just-stalking-women- without-their-knowledge-its-a-wake-up-call-about-facebook-privacy/
  64. 64. vielen dank.Stephan SchmidtHead of Web Sales Development1&1 Internet AGschst@php.netwww.schst.nettwitter.com/schst
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×