<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<p id="geolocation">获取地理位置坐标:</p>
<input type="button" οnclick="getlocation()" value="获取地理位置坐标"/>
<script>
var geo=document.getElementById('geolocation');
function getlocation(){
if(navigator.geolocation){
navigator.geolocation.getCurrentPosition(showposition,showerror);
}
else{
geo.innerHTML="not support!";
}
}
function showposition(position){
geo.innerHTML="经度latitude:"+position.coords.latitude+"<br>"+"纬度longititude:"+position.coords.longitude;
}
function showerror(error){
geo.innerHTML=error.code+" "+error.message;
}
</script>
</body>
</html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<p id="geolocation">获取地理位置坐标:</p>
<input type="button" οnclick="getlocation()" value="获取地理位置坐标"/>
<script>
var geo=document.getElementById('geolocation');
function getlocation(){
if(navigator.geolocation){
navigator.geolocation.getCurrentPosition(showposition,showerror);
}
else{
geo.innerHTML="not support!";
}
}
function showposition(position){
geo.innerHTML="经度latitude:"+position.coords.latitude+"<br>"+"纬度longititude:"+position.coords.longitude;
}
function showerror(error){
geo.innerHTML=error.code+" "+error.message;
}
</script>
</body>
</html>