【问题标题】:Cordova GeoLocation not applying lat long to json getCordova GeoLocation 未将 lat long 应用于 json get
【发布时间】:2017-12-13 00:24:44
【问题描述】:

我正在使用 Cordova Geolocation 插件来获取用户的经纬度数据。目的是使用该纬度和经度并将其应用于我正在对 Breezometer 进行的 api 调用。不幸的是,我的代码无法正常工作。有人可以让我知道我在这里缺少什么吗:

.controller('GeoCtrl', function($cordovaGeolocation, $scope, $http) {
var posOptions = {timeout: 10000, enableHighAccuracy: false};
$cordovaGeolocation
  .getCurrentPosition(posOptions)
  .then(function (position) {
    var lat  = position.coords.latitude
    var long = position.coords.longitude

    $scope.result = "";
    $http.get('https://api.breezometer.com/baqi/?lat='+ lat + 'lon=-' + long + '&key=c329a5b015f442748e088cfd13726267')
      .success(function(data, status, headers,config){
        console.log('data success');
        console.log(data); // for browser console
        $scope.result = data; // for UI
      })
      .error(function(data, status, headers,config){
        console.log('data error');
      })
      .then(function(result){
        things = result.data;
      });


  }, function(err) {
    // error
  });


var watchOptions = {
  frequency : 1000,
  timeout : 3000,
  enableHighAccuracy: false // may cause errors if true
};

var watch = $cordovaGeolocation.watchPosition(watchOptions);
watch.then(
  null,
  function(err) {
    // error
  },
  function(position) {
    var lat  = position.coords.latitude
    var long = position.coords.longitude
});


watch.clearWatch();
// OR
$cordovaGeolocation.clearWatch(watch)
  .then(function(result) {
    // success
    }, function (error) {
    // error
  });

})

【问题讨论】:

    标签: json cordova ionic-framework geolocation ngcordova


    【解决方案1】:

    http 请求的 url 错误。

    试试下面的,

    $http.get(https://api.breezometer.com/baqi/?lat='+ lat + '&lon='+ long +'&key='+ key)

    你在纬度和经度之间误判了&。并且 lon 不需要以 - 为前缀

    示例: https://api.breezometer.com/baqi/?lat=13.082680199999999&lon=80.2707184&key=c329a5b015f442748e088cfd13726267

    点击here查看结果。

    【讨论】:

      猜你喜欢
      • 2021-04-18
      • 1970-01-01
      • 2020-05-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-10
      相关资源
      最近更新 更多