在现有的ng-map上获取搜索框

时间:2017-01-17 12:49:06

标签: javascript angularjs google-maps

我需要将搜索框放到ng-map中。我从这里尝试解决方案

  

https://google-developers.appspot.com/maps/documentation/javascript/examples/geocoding-simple

但是我无法使用我的ng-map。这是我的plunker,如果有人可以帮我这个。我需要有两个解决方案,一个是放置标记并获取坐标(此解决方案正常工作),第二个是搜索框,我对此有疑问。是否有任何方法可以限制地图上的选择区域,例如此web site上的地图。我的英语不好。谢谢

  [1]: https://plnkr.co/edit/sKOaZOX6FbJwDdf3Po5Z?p=preview

1 个答案:

答案 0 :(得分:4)

ng-map library支持Place Autocomplete,有关详细信息,请参阅places-auto-complete.js

以下是启用地方自动填充的更改列表:

1)加载places这样的库:<script src="//maps.google.com/maps/api/js?key=--KEY--&libraries=places"></script>

2)在页面上放置input元素:<input places-auto-complete types="['geocode']" on-place-changed="placeMarker()" />

3)实现on-place-changed处理程序,例如:

$scope.placeMarker = function(){
    var place = this.getPlace();  //get selected place 
    //...
};

这是forked plunker,启用了搜索框