code_junkie

Geolocation API on the iPhone

Nov 11th, 2011
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.31 KB | None | 0 0
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head>
  5. <title>Geolocation API Demo</title>
  6. <meta content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;" name="viewport"/>
  7. <script>
  8. function successHandler(location) {
  9. var message = document.getElementById("message"), html = [];
  10. html.push("<img width='256' height='256' src='http://maps.google.com/maps/api/staticmap?center=", location.coords.latitude, ",", location.coords.longitude, "&markers=size:small|color:blue|", location.coords.latitude, ",", location.coords.longitude, "&zoom=14&size=256x256&sensor=false' />");
  11. html.push("<p>Longitude: ", location.coords.longitude, "</p>");
  12. html.push("<p>Latitude: ", location.coords.latitude, "</p>");
  13. html.push("<p>Accuracy: ", location.coords.accuracy, " meters</p>");
  14. message.innerHTML = html.join("");
  15. }
  16. function errorHandler(error) {
  17. alert('Attempt to get location failed: ' + error.message);
  18. }
  19. navigator.geolocation.getCurrentPosition(successHandler, errorHandler);
  20. </script>
  21. </head>
  22. <body>
  23. <div id="message">Location unknown</div>
  24. </body>
  25. </html>
  26.  
  27. <?xml version="1.0" encoding="UTF-8"?>
  28. <!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd">
  29. <html xmlns="http://www.w3.org/1999/xhtml">
  30. <head>
  31. <title>iPhone 4.0 geolocation demo</title>
  32. <meta content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;" name="viewport"/>
  33. <script>
  34. function handler(location) {
  35. var message = document.getElementById("message");
  36. message.innerHTML ="<img src='http://maps.google.com/maps/api/staticmap?center=" + location.coords.latitude + "," + location.coords.longitude + "&zoom=14&size=256x256&maptype=roadmap&sensor=false&markers=color:blue%7Clabel:ABC%7C" + location.coords.latitude + "," + location.coords.longitude + "' />";
  37.  
  38.  
  39.  
  40. message.innerHTML+="<p>Longitude: " + location.coords.longitude + "</p>";
  41. message.innerHTML+="<p>Accuracy: " + location.coords.accuracy + "</p>";
  42. message.innerHTML+="<p>Latitude: " + location.coords.latitude + "</p>";
  43.  
  44.  
  45.  
  46. }
  47. navigator.geolocation.getCurrentPosition(handler);
  48. </script>
  49. </head>
  50. <body>
  51. <div id="message">Location unknown</div>
  52. </body>
  53. </html>
Add Comment
Please, Sign In to add comment