案例:html案例     状态:可编辑再运行    进入横版
AخA
 
1
<!DOCTYPE html>
2
<html>
3
<body>
4
<p id="demo">点击这个按钮,获得您的坐标:</p>
5
<button onclick="getLocation()">试一下</button>
6
<script>
7
var x=document.getElementById("demo");
8
function getLocation()
9
  {
10
  if (navigator.geolocation)
11
    {
12
    navigator.geolocation.getCurrentPosition(showPosition,showError);
13
    }
14
  else{x.innerHTML="Geolocation is not supported by this browser.";}
15
  }
16
function showPosition(position)
17
  {
18
  x.innerHTML="Latitude: " + position.coords.latitude + 
19
  "<br />Longitude: " + position.coords.longitude;  
20
  }
21
function showError(error)
22
  {
23
  switch(error.code) 
24
    {

 运行结果 
 北美留学生论坛