0
我想获取地点信息like this example位置,城市,州,经度,纬度,使用place_id格式化地址。我得到错误Uncaught TypeError:undefined不是函数。我正在使用this: places/place-id google api获取地址。 var service = new google.maps.places.PlacesService(map);
内部使用地图变量因为我使用的是角度谷歌地图,所以我通过$scope.map
作为参数而不是map
。请检查下面的代码,我错了,我错误,因为通过$scope.map
在PlacesService
这是map
作为参数在this example。在Google Angular Map api中,如何使用place_id获取地点详细信息?
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>
控制器
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);
});
你从哪里得到“undefined不是函数”?你能粘贴错误跟踪吗? –
@ ZhenyangHua由于我在PlacesService中使用$ scope.map ......... – geeks
'PlacesService(attrContainer:HTMLDivElement | Map)',因此$ scope.map只是一个对象字面值,它不是'Map'类型或DOM。要获得'Map'类型的对象,可以使用'$ scope.map.control.getMap()'并将其解析为'PlacesService(map)'方法。 –