我想获取地点信息like this example位置、城市、州、经度、纬度、使用 place_id 的格式化_地址。我收到错误未捕获的类型错误:未定义不是函数。我正在使用this: places/place-id google api 用于获取地址。里面有使用 map 变量 var service = new google.maps.places.PlacesService(map);
因为我使用的是 angular-google-map,所以我传递 $scope.map
作为参数而不是 map
。请检查下面的代码,我错了,我的错误是由于在 PlacesService
中传递 $scope.map
需要 map
作为参数在 this example 。
HTML
<ui-gmap-google-map center='map.center' zoom='map.zoom' control='map.control' id="map-canvas">
<ui-gmap-markers models="markers" idkey="markers.id" coords="'coords'" >
</ui-gmap-markers>
</ui-gmap-google-map>
Controller
var map={
center: {
latitude:
longitude:
},
bounds : ,
zoom: 5,
control : {}
};
$scope.map = map;
var service = new google.maps.places.PlacesService($scope.map);
service.getDetails({ placeId: $scope.place_id}, function(place, status){
console.log('place='+place);
});
最佳答案
根据上面的评论,var map=$scope.map.control.getGMap()
是解决方案。
因此,对于使用 angular-google-map 的其他人,您需要使用 $scope.map.control.getGMap()
来获取当前 map 实例。
关于javascript - 在 Google Angular Map api 中,如何使用 place_id 获取地点详细信息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33221815/