IBM MobileFirst——获取位置

IBM MobileFirst -- get location

我有 MobileFirst (V7.O) 应用程序。如何获取设备的当前 latitude/Longitude。基本上,我在我的应用程序的不同点记录一些信息,用户可以移动..所以,在各种情况下,我想获得当前的 lat/log..

能否提供一些提示以及如何获取此信息

感谢您的帮助

Cordova 捆绑在您的 MobileFirst 项目中。因此,您可以使用 Cordova APIs 来实现这一点。

查看以下内容(向下滚动到 API 用法):https://github.com/apache/cordova-plugin-geolocation

// onSuccess Callback
// This method accepts a Position object, which contains the
// current GPS coordinates
//
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);