xml/html Code copy content to clipboard
- <! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 strict//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
- <html xmlns= "http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
- <head>
- <meta http-equiv= "content-type" content= "text/html; Charset=utf-8 ">
- <title>geolocation object, geolocation interaction with Google Map------JS
- Mix</title>
- </head>
- <body>
- <input type="button" id="GetPos" value="Get my Location">
- <div id="info" class= "">
- You are here: Longitude
- <span class="Tip">unknown</span, latitude
- <span class="Tip">unknown</span>
- </div>
- <script type="Text/javascript">
- var t = 0;
- var dom = {
- Btn:document.getElementById (' GetPos '),
- Info:document.getElementById (' info ')
- };
- Dom.btn.onclick = function () {
- if (navigator.geolocation) {
- Dom.info.innerHTML = "Please wait for query results to return";
- dom.info.className = "Warn";
- Navigator.geolocation.getCurrentPosition (getpositionsuccess,getpositionerror,{timeout:5000});
- }else {
- Dom.info.innerHTML = "Sorry, the browser you are using does not support the Geolocation interface";
- dom.info.className = "Warn";
- }
- }
- function getpositionsuccess (position) {
- var lat = position.coords.latitude;
- var lng = position.coords.longitude;
- Dom.info.innerHTML = "Your location: Longitude" + lat + ", latitude" + LNG;
- if (typeof position.address = = = = "undefined") {
- Dom.info.innerHTML + = "<br /><span class=' tip '> Your browser currently only provides coordinate queries, using Firefox 3.5+ can get more information </span> ";
- }else{
- Dom.info.innerHTML + = "<br /><span class=' tip '>" + Position.address.country + "," + Position.address.region + "," + position.address.city+ "</span>";
- }
- }
- function Getpositionerror (Error) {
- Switch (error.code) {
- Case error. TIMEOUT:
- Dom.info.innerHTML = "Connection timed out, please retry";
- Break
- Case error. Permission_denied:
- Dom.info.innerHTML = "You refused to use Location sharing service, the query was canceled";
- Break
- Case error. Position_unavailable:
- Dom.info.innerHTML = "Dear Mars netizen, very sorry <br/> We are temporarily unable to provide location services for your planet";
- Break
- }
- }
- </Script>
- </Body>
- </html>
Use HTML5 for geo-location targeting. Error in +-500m