HTML5 authoritative guide 15. Obtaining Geo-location information

Source: Internet
Author: User

1Navigator.geolocation.getCurrentPosition (function(position) {2                 varcoords=position.coords;3 Console.log (coords.latitude,coords.longitude,coords.accuracy);4             },5             //Catching error Messages6             function(Error) {7                 varErrortype={81: ' Location service is denied ',92: "Cannot get location information",Ten3: "Get information timeout" One                 }; AAlert (errortypes[error.code]+ ": Unable to get your current location"); -})

1 <!DOCTYPE HTML>2 <HTML>3 4     <Head>5         <MetaCharSet= "UTF-8">6         <title></title>7         <Scripttype= "Text/javascript">8             functionShowobject (obj, k) {9                 //recursive display of objectTen                 if(!obj) { return; } One                  for(varIinchobj) { A                     if(typeof(Obj[i]!= "Object" ||Obj[i]== NULL)) { -                          for(varJ= 0; J<K; J++) { - document.write ("&nbsp;&nbsp;&nbsp;&nbsp;"); the                         } - document.write (i+ ":" +Obj[i]+ "<br/>"); -                     } Else { - document.write (i+ ":<br/>"); + Showobject (Obj[i], K+ 1); -                     } +                 } A             } at  -             functionget_location () { -                 if(navigator.geolocation) - navigator.geolocation.getCurrentPosition (Show_map, Handle_error, {enablehighaccuracy:true, Maximumage: + }); -                 Else - Alert ("not supported"); in             } -  to             functionHandle_error (err) { +                 //Error Handling -                 Switch(err.code) { the                      Case 1: * Alert ("location service is denied"); $                          Break;Panax Notoginseng                      Case 2: - Alert ("location service is denied"); the                          Break; +                      Case 3: A Alert ("location service is denied") the                          Break; +                     default: - Alert ("Unknown error") $                          Break; $                 } -             } -  the             functionShow_map (position) { -                 //displaying geographic informationWuyi                 varLatitude=Position.coords.latitude; the                 varLongitude=Position.coords.longitude; - showobject (position,0); Wu             } - get_location (); About         </Script> $     </Head> -  -     <Body> -         <DivID= "Map"style= "width:400px; height:400px;"></Div> A     </Body> +  the </HTML>

HTML5 authoritative guide 15. Obtaining Geo-location information

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.