html5获取当前经纬度

获取用户当前位置的经纬度,用HTML5代码如下:

[php]

点击按钮获取您当前坐标(可能需要比较长的时间获取):

<button onclick="getLocation()">点我</button>
<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" data-wp-preserve="%3Cscript%3E%0Avar%20x%3Ddocument.getElementById(%22demo%22)%3B%0Afunction%20getLocation()%0A%7B%0Aif%20(navigator.geolocation)%0A%7B%0Anavigator.geolocation.getCurrentPosition(showPosition)%3B%0A%7D%0Aelse%7Bx.innerHTML%3D%22%E8%AF%A5%E6%B5%8F%E8%A7%88%E5%99%A8%E4%B8%8D%E6%94%AF%E6%8C%81%E8%8E%B7%E5%8F%96%E5%9C%B0%E7%90%86%E4%BD%8D%E7%BD%AE%E3%80%82%22%3B%7D%0A%7D%0Afunction%20showPosition(position)%0A%7B%0Ax.innerHTML%3D%22%E7%BA%AC%E5%BA%A6%3A%20%22%20%2B%20position.coords.latitude%20%2B%0A%22%3Cbr%3E%E7%BB%8F%E5%BA%A6%3A%20%22%20%2B%20position.coords.longitude%3B%0A%7D%0A%3C%2Fscript%3E" data-mce-resize="false" data-mce-placeholder="1" class="mce-object" width="20" height="20" alt="&lt;script&gt;" title="&lt;script&gt;" />[/php]

您可能还喜欢...

1 条回复

  1. cialis generic说道:

    You said it perfectly..

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注