百度地图根据经纬度

var map = new BMap.Map("map");
var point = new BMap.Point(116.404, 39.915);
map.centerAndZoom(point, 15);
map.enableScrollWheelZoom(); // 开启鼠标滚轮缩放
map.addControl(new BMap.ScaleControl()); // 添加比例尺控件

var pointStr = "104.038748,30.641821,104.047789,30.648128,104.063959,30.655336,104.067264,30.660307,104.067264,30.664438,104.064008,30.665316".split(",");
var pointArr = [];

for (var k = 0; k < pointStr.length; k += 2) {
pointArr.push({
lng: pointStr[k],
lat: pointStr[k + 1]
});
}

// 生成坐标点
var trackPoint = [];
for (var i = 0, j = pointArr.length; i < j; i++) {
trackPoint.push(new BMap.Point(pointArr[i].lng, pointArr[i].lat));
}

map.centerAndZoom(trackPoint[0], 15);

// 画线
var polyline = new BMap.Polyline(trackPoint, {
strokeColor: "#1869AD",
strokeWeight: 3,
strokeOpacity: 1
});
map.addOverlay(polyline);

// 配置图片
var size = new BMap.Size(26, 26);
var offset = new BMap.Size(0, -13);
var imageSize = new BMap.Size(26, 26);
var icon = new BMap.Icon("./express-position.png", size, {
imageSize: imageSize
});

posted on 2019-08-05 18:23  激流勇进1  阅读(210)  评论(0编辑  收藏  举报