JavaScript JavaScript GeoLocation
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JavaScript JavaScript GeoLocation相关的知识,希望对你有一定的参考价值。
<!DOCTYPE html>
<html>
<head>
<title></title>
<script src="geoLocation.js"></script>
<style>
div#location {
border: 1px solid #000000;
height: 300px;
margin-left: 25%;
margin-top: 5%;
padding: 10px 5px 10px 5px;
width: 50%;
}
</style>
</head>
<body>
<div id="location">
</div>
<script>
/**
* Sample GeoLocation Script
* Adam Shannon
* 06/26/2009
*/
function getLocation() {
// First we must test to see if GeoLocation is even supported.
if (navigator.geolocation) {
// Now wee can start the service.
// navigator.geolocation.startup();
// Check to see if the API is ready.
// if (!navigator.geolocation.isReady()) {
// alert("Whoops, your GeoLocation API is not currently ready");
// }
// Make the call
// navigator.geolocation.getCurrentPosition(success, fail, options);
navigator.geolocation.getCurrentPosition(function(position) {
fillDiv(
position.coords.latitude,
position.coords.longitude,
position.coords.altitude,
position.coords.accuracy,
position.coords.altitudeAccuracy,
position.coords.heading,
position.coords.speed
);
});
// Shut it down
// navigator.geolocation.shutdown();
} else {
alert("Whoops, it seems like your browser doesn't support GeoLocation.");
}
return;
}
function fillDiv(latitude, longitude, altitude, accuracy, altitudeAccuracy, heading, speed) {
// Go...
// alert(latitude);
// alert(longitude);
var e = document.getElementById("location");
e.innerHTML = "";
e.innerHTML += "Latitude: " + latitude + "<br />";
e.innerHTML += "Longitude: " + longitude + "<br />";;
e.innerHTML += "Altitude: " + altitude + "<br />";;
e.innerHTML += "Accuracy: " + accuracy + "<br />";;
e.innerHTML += "altitudeAccuracy: " + altitudeAccuracy + "<br />";;
e.innerHTML += "Heading: " + heading + "<br />";;
e.innerHTML += "Speed: " + speed;
return;
}
// Now call
getLocation();
</script>
</body>
</html>
以上是关于JavaScript JavaScript GeoLocation的主要内容,如果未能解决你的问题,请参考以下文章
javascript 获取IP相关信息,包括GEO信息
JavaScript WordPress Geo Mashup Mapstraction自定义标记
两个 GEO 位置之间的距离 [重复]
Sencha Touch - Map.Geo = null
Google Geo Charts 未通过 ajax 调用加载
在php循环中写入javascript数组