高德demo地址:http://lbs.amap.com/api/javascript-api/example/amap-ui-poipicker/index
高德地图结合angular4 实现下拉框获取某一个点的poi信息。
实现步骤:
第一步:在index.html中引入高德地图相关api。根据具体项目的需求建立不同的项目获取不同key值
<link rel="stylesheet" href="http://cache.amap.com/lbs/static/main1119.css"/> <script src="http://webapi.amap.com/maps?v=1.4.3&key=1d54cf0e4dac3ed6da30cbad7627dcdd&plugin=AMap.PlaceSearch"></script> <script src="http://webapi.amap.com/ui/1.0/main.js?v=1.0.11"></script>
第二步:在相应html中添加下拉框
<div class="col-sm-3 "> <input id="pickerInput" class="form-control" [(ngModel)]="content" (ngModelChange)="change()" > <div style="color:white" id="poiResult"></div> </div>
第三步:相应ts中获取信息
declare var AMapUI: any; change() { let content = this.content; console.log(content); AMapUI.loadUI(['misc/PoiPicker'],function(PoiPicker) { var poiPicker = new PoiPicker({ input: 'pickerInput',}); poiPicker.on('poiPicked',function(poiResult) { var source = poiResult.source,poi = poiResult.item,info = { source: source,id: poi.id,name: poi.name,location: poi.location.toString(),address: poi.address }; }); }); }