Navigator. geolocation example classification: javascript 1601 people read comments (0) collect reports function Browser
[HTML]View plaincopy
- <HTML>
- <Head>
- <SCRIPT type = "text/JavaScript">
- Function getpositionsuccess (position ){
- VaR lat = position. coords. Latitude;
- VaR lng = position. coords. longpolling;
- Document. Write ("Location: longitude (" + lat + "), latitude (" + LNG + ")");
- If (typeof position. Address! = "Undefined "){
- VaR Country = position. Address. Country;
- VaR province = position. Address. region;
- VaR city = position. Address. City;
- Document. Write ("<br/> ");
- Document. Write ("You are located in" + country + province + city );
- }
- }
- Function getpositionerror (error ){
- Switch (error. Code ){
- Case Error. Timeout:
- Alert ("connection timed out, please try again ");
- Break;
- Case Error. permission_denied:
- Alert ("You refused to use location sharing service, query canceled ");
- Break;
- Case Error. position_unavailable:
- Alert ("Dear Mars, sorry, we are not able to provide location services for your planet ");
- Break;
- }
- }
- </SCRIPT>
- </Head>
- <Body>
- <SCRIPT type = "text/JavaScript" src = "http://maps.google.com/maps/api/js? Sensor = true "> </SCRIPT>
- <SCRIPT type = "text/JavaScript">
- If (navigator. geolocation ){
- Navigator. geolocation. getcurrentposition (getpositionsuccess, getpositionerror );
- } Else {
- Alert ("your browser does not support geolocation! ");
- }
- </SCRIPT>
- </Body>
- </Html>
Reprinted: http://blog.csdn.net/gohome520/article/details/7338486
Example of navigator. Geolocation