Angular google.maps.event.addListener('place_changed', 函数() {});不工作
Angular google.maps.event.addListener('place_changed', function() {}); not working
我正在添加 '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);
});
}
}
谢谢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); } }
我正在添加 '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);
});
}
}
谢谢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); } }