<!DOCTYPE html> <html> <head> <title>Location</title> <meta charset="utf-8"> </head> <body> <input type="button" id="btnLocation" value="获取位置信息"> </body> <script src="jquery.min.js"></script> <script type="text/javascript"> //检测是否支持地理信息 function isSupportGeo(){ return (navigator.geolocation!=null); } //绑定click事件 $("#btnLocation").click(function () { if(!isSupportGeo()){ alert("浏览器不支持地理位置信息定位!"); }else{ navigator.geolocation.getCurrentPosition(doSucc,doFail); } }); //处理成功 function doSucc(position) { //alert("成功获取地理信息!"); alert("经度:"+position.coords.longitude+"纬度:"+position.coords.latitude); } //处理失败 function doFail(error) { alert("获取地理信息失败!"); } </script> </html>