Angular google.maps.event.addListener(' place_changed',function(){});不工作

时间:2015-07-22 11:57:11

标签: angularjs google-maps addeventlistener eventtrigger angular-google-maps

我正在添加' place_changed'听众在我搜索地址时第一次没有工作,而后来工作完美。谁能告诉我应该做些什么。这是我的代码。在此先感谢您的支持

var events = {
      places_changed: function (searchBox) {
        var gPlace = new google.maps.places.Autocomplete(document.getElementById('map-search-box'));
        google.maps.event.addListener(gPlace, 'place_changed', function() {

          var place = gPlace.getPlace();

          var a =place.geometry.location;

    $scope.myLocation = {
      lng : place.geometry.location.D,
      lat: place.geometry.location.k
    }
    abc = {
      coords: {
        latitude: place.geometry.location.k,
        longitude:place.geometry.location.D
      }

  }
     $scope.drawMap(abc); 
}); 

}

}

1 个答案:

答案 0 :(得分:0)

谢谢KayAnn我已经解决了这个问题。实际上我从未检查过函数(searchBox){} searchBox它的对象,这些对象证明了我需要的所有数据,所以这里是更新的代码,工作正常

var events = {
      places_changed: function (searchBox) {
       var lat = searchBox.getPlaces()[0].geometry.location.k;
       var lgn = searchBox.getPlaces()[0].geometry.location.D;

        $scope.myLocation = {
        lng : searchBox.getPlaces()[0].geometry.location.D,
        lat: searchBox.getPlaces()[0].geometry.location.k
      }

      abc = {
        coords: {
        latitude: searchBox.getPlaces()[0].geometry.location.k,
        longitude:searchBox.getPlaces()[0].geometry.location.D
        } 
       }
           $scope.drawMap(abc); } }