Use HTML5 for geo-location targeting. Error in +-500m

Source: Internet
Author: User

xml/html Code copy content to clipboard
  1. <!  DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 strict//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <html xmlns= "http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  3. <head>
  4. <meta http-equiv= "content-type" content= "text/html; Charset=utf-8 ">
  5. <title>geolocation object, geolocation interaction with Google Map------JS
  6. Mix</title>
  7. </head>
  8. <body>
  9. <input type="button" id="GetPos" value="Get my Location">
  10. <div id="info" class= "">
  11. You are here: Longitude
  12. <span class="Tip">unknown</span, latitude
  13. <span class="Tip">unknown</span>
  14. </div>
  15. <script type="Text/javascript">
  16. var t = 0;
  17. var dom = {
  18. Btn:document.getElementById (' GetPos '),
  19. Info:document.getElementById (' info ')
  20. };
  21. Dom.btn.onclick = function () {
  22. if (navigator.geolocation) {
  23. Dom.info.innerHTML = "Please wait for query results to return";
  24. dom.info.className = "Warn";
  25. Navigator.geolocation.getCurrentPosition (getpositionsuccess,getpositionerror,{timeout:5000});
  26. }else {
  27. Dom.info.innerHTML = "Sorry, the browser you are using does not support the Geolocation interface";
  28. dom.info.className = "Warn";
  29. }
  30. }
  31. function getpositionsuccess (position) {
  32. var lat = position.coords.latitude;
  33. var lng = position.coords.longitude;
  34. Dom.info.innerHTML = "Your location: Longitude" + lat + ", latitude" + LNG;
  35. if (typeof position.address = = = = "undefined") {
  36. Dom.info.innerHTML + = "<br /><span class=' tip '> Your browser currently only provides coordinate queries, using  Firefox 3.5+ can get more information </span> ";
  37. }else{
  38. Dom.info.innerHTML + = "<br /><span class=' tip '>" +  Position.address.country + "," + Position.address.region + "," + position.address.city+ "</span>";
  39. }
  40. }
  41. function Getpositionerror (Error) {
  42. Switch (error.code) {
  43. Case error. TIMEOUT:
  44. Dom.info.innerHTML = "Connection timed out, please retry";
  45. Break
  46. Case error. Permission_denied:
  47. Dom.info.innerHTML = "You refused to use Location sharing service, the query was canceled";
  48. Break
  49. Case error. Position_unavailable:
  50. Dom.info.innerHTML = "Dear Mars netizen, very sorry <br/> We are temporarily unable to provide location services for your planet";
  51. Break
  52. }
  53. }
  54. </Script>
  55. </Body>
  56. </html>

Use HTML5 for geo-location targeting. Error in +-500m

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.