if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(geolocationSuccess, geolocationFailure); } else { console.log("此浏览器不支持地理定位。"); } // 查询成功将调用的函数 var geolocationSuccess = function(pos) { console.log("您的位置是 " + pos.coords.latitude + "°, " + pos.coords.longitude + "°."); }; // 查询失败时将调用的函数 var geolocationFailure = function(err) { console.log("ERROR (" +err.code+ "): " + err.message); };