javascript - 在 Google Angular Map api 中,如何使用 place_id 获取地点详细信息?

标签 javascript angularjs google-maps google-maps-api-3

我想获取地点信息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/

相关文章:

javascript - 谷歌街景不显示在 wordpress 标签中

javascript - 无法从 JavaScript 中的 JSON 数组获取值

javascript - 使用 mongojs 添加依赖于其他查询的额外字段来查询 mongodb 中的结果

javascript - 单击 HTML 元素时更改数据属性

javascript - vuejs - 使用谷歌地图的 Safari 浏览器导航

javascript - setInterval/clearInterval 范围内的问题

javascript - 在 WebStorm 中编译 .coffee 文件

angularjs - Web应用程序前端和后端的误解

javascript - AngularJS 自定义排序指令

javascript - 更新指令内的 attrs 值 - 如何在 AngularJS 中执行此操作