iOS设备上的Meteor Geocoder,仅返回lat和lng,但不返回物理地址

时间:2015-08-07 17:29:37

标签: ios google-maps meteor google-geocoder

我正在使用Meteor开发iOS应用程序。当我应用浏览器端API"时,我可以完美地恢复浏览器上的物理地址。但是,它不适用于iOS模拟器或iOS设备。 所以,我为iOS应用程序应用了另一个APIKey。它仍然无法运作。请指教。

有时它有效,但大部分时间,实际地址结果都没有回来。

//router.js
Router.route('/',{
    path:"/",
    onBeforeAction: function() {
        Session.set('geoLocation',Geolocation.latLng());
        console.log(Geolocation.latLng());
        this.next();
    }
});

//index.html
<head>
  <title>Todo List</title>
</head>

<body>
  <div class="container">
    <header>
      <h1>Todo List</h1>
      <div class="item">
        hi
      </div>
    </header>
    <input class="address" type="search" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" name="address" placeholder="Address" value="#">
</div>
</body>

//server.js
if (Meteor.isClient) {
  if (Session.get('geoLocation')){
    var temp = Session.get('geoLocation');
    var lat = temp.lat;
    var lng = temp.lng;
    Meteor.call('getPhysicalAddress', lat, lng, function(err, result){
      console.log(result);
      console.log(result[0].city);
      Session.set('physicalAddress', result[0].city);
      physicalAddress = Session.get('physicalAddress');
    });
  }

  Template.body.events({
    'click .address': function(e){
      var a = Session.get('physicalAddress');
      $('.container').append('<h1>'+a+'</h1>');
      $('.address').val(Session.get('physicalAddress'));
      console.log('im here');
    }
  });


}


if (Meteor.isServer) {
  Meteor.methods({
    'getPhysicalAddress':function(lat,lng) {
      var geo = new GeoCoder({
        geocoderProvider: "google",
        apiKey: 'xxx',
        httpAdapter: "https"
      });
      return geo.reverse(lat,lng);
    },

    'getGoogleAddress':function(address) {
      check(address,String);
      var geo = new GeoCoder({
        geocoderProvider: "google",
        apiKey: 'xxx',
        httpAdapter: "https"
      });
      return geo.geocode(address)[0];
    }
  });
}

0 个答案:

没有答案