Example of navigator. Geolocation

Source: Internet
Author: User
Navigator. geolocation example classification: javascript 1601 people read comments (0) collect reports function Browser



[HTML]View plaincopy
    1. <HTML>
    2. <Head>
    3. <SCRIPT type = "text/JavaScript">
    4. Function getpositionsuccess (position ){
    5. VaR lat = position. coords. Latitude;
    6. VaR lng = position. coords. longpolling;
    7. Document. Write ("Location: longitude (" + lat + "), latitude (" + LNG + ")");
    8. If (typeof position. Address! = "Undefined "){
    9. VaR Country = position. Address. Country;
    10. VaR province = position. Address. region;
    11. VaR city = position. Address. City;
    12. Document. Write ("<br/> ");
    13. Document. Write ("You are located in" + country + province + city );
    14. }
    15. }
    16. Function getpositionerror (error ){
    17. Switch (error. Code ){
    18. Case Error. Timeout:
    19. Alert ("connection timed out, please try again ");
    20. Break;
    21. Case Error. permission_denied:
    22. Alert ("You refused to use location sharing service, query canceled ");
    23. Break;
    24. Case Error. position_unavailable:
    25. Alert ("Dear Mars, sorry, we are not able to provide location services for your planet ");
    26. Break;
    27. }
    28. }
    29. </SCRIPT>
    30. </Head>
    31. <Body>
    32. <SCRIPT type = "text/JavaScript" src = "http://maps.google.com/maps/api/js? Sensor = true "> </SCRIPT>
    33. <SCRIPT type = "text/JavaScript">
    34. If (navigator. geolocation ){
    35. Navigator. geolocation. getcurrentposition (getpositionsuccess, getpositionerror );
    36. } Else {
    37. Alert ("your browser does not support geolocation! ");
    38. }
    39. </SCRIPT>
    40. </Body>
    41. </Html>

Reprinted: http://blog.csdn.net/gohome520/article/details/7338486

Example of navigator. Geolocation

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.