HTML5之地理信息应用 获取自己的位置
上代码:
window.onload = function() { if (navigator.geolocation) { navigator.geolocation.getCurrentPosition( function(pos) { $(“lat”).innerHTML = pos.coords.latitude;//纬度 $(“lon”).innerHTML = pos.coords.longitude;// 经度 $(“alt”).innerHTML = pos.coords.altitude;//高度 }, function() {},{ enableHighAccuracy:true, maximumAge:600000} ); } else { $("status").innerHTML = '你的浏览器不支持'; }
- 部分浏览器可以提供更详细的地址信息
{"coords": ..// ... "address": {"streetNumber":"6","street":"Postgasse", "premises":null,"c ity":"Murnau am Staffelsee", "county":"Garmisch ‐Partenkirchen","region":"Bavaria", "country":"Germany","countryCode":"DE", "postalCode":"82418","contractID":"", "classDescription":"wifi geo position address object", // ... }, // ... }