Taro之百度地图显示定位点和信息
由于没有后台数据就随机生成点来模拟了。具体代码如下。
componentDidMount = () => { const { BMap, BMAP_STATUS_SUCCESS } = window let map = new BMap.Map("container") let poi let geolocation = new BMap.Geolocation() geolocation.getCurrentPosition(function (r) { if (this.getStatus() == BMAP_STATUS_SUCCESS) { poi = new BMap.Point(r.longitude, r.latitude) map.centerAndZoom(poi, 15) function addMarker(point, index) { let myIcon = new BMap.Icon(businessl, new BMap.Size(20, 20), { anchor: new BMap.Size(0, 0), imageOffset: new BMap.Size(0, 0 + index - index), imageSize: new BMap.Size(20, 20), infoWindowAnchor: new BMap.Size(0, 0) }) let marker = new BMap.Marker(point, { icon: myIcon }) map.addOverlay(marker) marker.addEventListener("click", function () { let opts = { width: 200, height: 100, title: String(index) } let infoWindow = new BMap.InfoWindow(String(index), opts) marker.openInfoWindow(infoWindow) }) } let bounds = map.getBounds() console.log(bounds) let lngSpan = bounds.He - bounds.Le let latSpan = bounds.Vd - bounds.Xd for (let i = 0; i < 10; i++) { let point = new BMap.Point(bounds.Le + lngSpan * (Math.random() * 0.7 + 0.15), bounds.Xd + latSpan * (Math.random() * 0.7 + 0.15)) addMarker(point, i) } } }) };
SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。

更多精彩