如何使用 Google Maps API V3 对地图添加多个标注
1个回答
展开全部
Google Maps V3 在线地图的使用(一):多个坐标之间连线
引入GoogleMap的js
1<script type="text/javascript"src="http://maps.google.com/maps/api/js?sensor=false"></script>
创建几个坐标
//所有坐标
varlocations = newArray( "31.953313,121.841581","31.15347,121.291706", "31.207516,121.412556","31.122909,121.458561", "31.118207,121.38715","31.041168,121.426289", "30.985262,121.301319","31.057934,121.305834");
加载地图的方法
functioninitialize() { varlatlng = newgoogle.maps.LatLng(31.253313, 121.241581); varmyOptions ={ zoom: 10, //缩放级别
center: latlng, //坐标
mapTypeId: google.maps.MapTypeId.ROADMAP //类型:默认的普通二维图块
}; map = newgoogle.maps.Map(document.getElementById("map_canvas"), myOptions); //线条设置
varpolyOptions ={ strokeColor: '#000000', //颜色
strokeOpacity: 1.0, //透明度
strokeWeight: 2 //宽度
} poly = newgoogle.maps.Polyline(polyOptions); poly.setMap(map); //装载
/*循环标出所有坐标 */
for(vari=0; i<locations.length; i++){ varloc = locations[i].split(','); varpath = poly.getPath(); //获取线条的坐标
path.push(newgoogle.maps.LatLng(loc[0], loc[1])); //为线条添加标记坐标
//生成标记图标
marker = newgoogle.maps.Marker({ position: newgoogle.maps.LatLng(loc[0], loc[1]), map: map, icon: "http://labs.google.com/ridefinder/images/mm_20_green.png"
}); } }
引入GoogleMap的js
1<script type="text/javascript"src="http://maps.google.com/maps/api/js?sensor=false"></script>
创建几个坐标
//所有坐标
varlocations = newArray( "31.953313,121.841581","31.15347,121.291706", "31.207516,121.412556","31.122909,121.458561", "31.118207,121.38715","31.041168,121.426289", "30.985262,121.301319","31.057934,121.305834");
加载地图的方法
functioninitialize() { varlatlng = newgoogle.maps.LatLng(31.253313, 121.241581); varmyOptions ={ zoom: 10, //缩放级别
center: latlng, //坐标
mapTypeId: google.maps.MapTypeId.ROADMAP //类型:默认的普通二维图块
}; map = newgoogle.maps.Map(document.getElementById("map_canvas"), myOptions); //线条设置
varpolyOptions ={ strokeColor: '#000000', //颜色
strokeOpacity: 1.0, //透明度
strokeWeight: 2 //宽度
} poly = newgoogle.maps.Polyline(polyOptions); poly.setMap(map); //装载
/*循环标出所有坐标 */
for(vari=0; i<locations.length; i++){ varloc = locations[i].split(','); varpath = poly.getPath(); //获取线条的坐标
path.push(newgoogle.maps.LatLng(loc[0], loc[1])); //为线条添加标记坐标
//生成标记图标
marker = newgoogle.maps.Marker({ position: newgoogle.maps.LatLng(loc[0], loc[1]), map: map, icon: "http://labs.google.com/ridefinder/images/mm_20_green.png"
}); } }
追答
全部代码:
Locus
//所有坐标
varlocations =newArray( "31.953313,121.841581","31.15347,121.291706", "31.207516,121.412556","31.122909,121.458561", "31.118207,121.38715","31.041168,121.426289", "30.985262,121.301319","31.057934,121.305834"); //地图
varmap; varmarker; varpoly; /*加载地图 */
functioninitialize() { varlatlng =newgoogle.maps.LatLng(31.253313, 121.241581); varmyOptions ={ zoom: 10, //缩放级别
center: latlng, //坐标
mapTypeId: google.maps.MapTypeId.ROADMAP //类型:默认的普通二维
引用:博客园
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
AiPPT
2024-09-19 广告
2024-09-19 广告
随着AI技术的飞速发展,如今市面上涌现了许多实用易操作的AI生成工具1、简介:AiPPT: 这款AI工具智能理解用户输入的主题,提供“AI智能生成”和“导入本地大纲”的选项,生成的PPT内容丰富多样,可自由编辑和添加元素,图表类型包括柱状图...
点击进入详情页
本回答由AiPPT提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询