通过HTML5地理定位API以外的方式识别用户的地理位置

Identifying geolocation of user by other than HTML5 Geolocation API

本文关键字:方式 识别 用户 地理位置 HTML5 定位 API 通过      更新时间:2023-09-26

我正在用Jsp编写一个web应用程序,它需要识别用户的地理位置。我尝试过使用HTML5地理定位api的w3schools的代码。但是它没有在Tomcat上执行。我在这里张贴了这个问题,但没有解决方案。所以我认为这是不可能的。

所以现在我正在寻找替代方法来做同样的事情。我的问题是,是否有其他方法可以让我识别用户的当前位置?实际上,我是网络技术的新手。所以如果有人对此有任何建议,我将非常感激。谢谢你。

EDIT:是否可以使用whois来识别用户的位置?

您可以使用corodva JS在HTML5应用程序中获得地理位置http://docs.phonegap.com/en/2.5.0/cordova_geolocation_geolocation.md.html

var onSuccess = function(position) {
alert('Latitude: '          + position.coords.latitude          + ''n' +
      'Longitude: '         + position.coords.longitude         + ''n' +
      'Altitude: '          + position.coords.altitude          + ''n' +
      'Accuracy: '          + position.coords.accuracy          + ''n' +
      'Altitude Accuracy: ' + position.coords.altitudeAccuracy  + ''n' +
      'Heading: '           + position.coords.heading           + ''n' +
      'Speed: '             + position.coords.speed             + ''n' +
      'Timestamp: '         + position.timestamp                + ''n');
};
// onError Callback receives a PositionError object
function onError(error) {
alert('code: '    + error.code    + ''n' +
      'message: ' + error.message + ''n');
}
navigator.geolocation.getCurrentPosition(onSuccess, onError);