高德地图-设置直线路线

1、问题背景

给点了地图上两个坐标,然后连接两个点,成为一条直线


2、实现源码

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
    	<meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
		<title>高德地图-设置直线路线</title>
		<link rel="stylesheet" href="http://cache.amap.com/lbs/static/main1119.css"/>
    	<script src="http://webapi.amap.com/maps?v=1.3&key=c2eb520334ddc5ab2bb70a3afe6a58cc"></script>
    	<script type="text/javascript" src="http://cache.amap.com/lbs/static/addToolbar.js"></script>
    	<style>
    		html,body{
    			width: 100%;
    			height: 100%;
    			font-family: "微软雅黑";
    			font-size: 12px;
    			font-feature-settings: normal;
    			font-size-adjust: initial;
    			font-stretch: extra-condensed;
    			font-synthesis: initial;
    		}
    		#lineMap{
    			width: 100%;
    			height: 100%;
    			font-size: 12px;
    			font-family: "arial, helvetica, sans-serif";
    		}
    	</style>
	</head>
	<body>
		<div id="lineMap"></div>
		<script>
			//实例化和初始化地图
			var map = new AMap.Map('lineMap', {
        		resizeEnable: true,
        		center: [114.295482,30.582582],
        		zoom: 14
    		});
    		
    		//选定两个坐标
    		var line = [
    			[114.254283,30.567507],
    			[114.328098,30.54489]
    		];
    		
    		//设置连接线样式
    		var polyline = new AMap.Polyline({
        		path: line,          //设置线覆盖物路径
        		strokeColor: "#FF0000", //线颜色
        		strokeOpacity: 0.8,       //线透明度
        		strokeWeight: 1,        //线宽
        		strokeStyle: "dashed",   //线样式
        		strokeDasharray: [10, 10] //补充线样式
    		});
    		
    		polyline.setMap(map);
		</script>
	</body>
</html>

3、实现结果


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值