谷歌地图JavaScript API V3,Lat/Lon点的绘图数组
Google Maps JavaScript API V3, plot array of Lat/Lon Points
我正在尝试创建一个简单的谷歌地图,它将遍历Lat/Lon对的多维数组并绘制它们。如果for循环被注释掉,则地图将显示。提前谢谢。
这是我的代码:
<script type="text/javascript">
function initialize()
{
var map;
var mapOptions =
{
zoom: 9,
center: new google.maps.LatLng(39.03454, -94.587315),
mapTypeId: google.maps.MapTypeId.ROADMAP,
};
map = new google.maps.Map(document.getElementById('body-space-inside'), mapOptions);
var business_locations =
[
['South Plaza', '5105 Main St Kansas City, MO 64112', '39.03454', '-94.587315'],
['City Market', '427 Main Street Kansas City, MO 64105', 39.108518, -94.582635],
['Barry Road East', '221 Northeast Barry Road Kansas City, MO 64155', 39.246116, -94.57759],
['Barry Road West', '7007 NW Barry Road Kansas City, MO 64153', 39.246116, -94.57759],
['Shawnee', '7198 Renner Road Shawnee, KS 66217', 38.999569, -94.779798],
['Blue Springs', '2201 NW State Route 7 Blue Springs, MO 64014', 39.04395, -94.271227],
['Leawood', '12920 State Line Road Leawood, KS 66209', 38.893127, -94.607991],
['Lenexa', '13400 College Boulevard Lenexa, KS 66210', 38.927529, -94.741263],
['Olathe', '15983 S Bradley Drive Olathe, KS 66062', 38.838983, -94.778771],
['Prarie Village', '6921 Tomahawk Rd Prairie Village, KS 66208', 39.003414, -94.631471],
['Independence', '2551 S State Route 291 Independence, MO 64057', 39.073201, -94.378762],
['Lees Summit', '632 NE State Route 291 Lees Summit, MO 64086', 38.923416, -94.360608],
['Liberty', '205 N 291 Highway Liberty, MO 64068', 39.246472, -94.443878];
];
for(var i = 0; i < business_locations.length; i++)
{
var marker = new google.maps.Marker({
position: new google.maps.Latlng(business_locations[i][2], business_locations[i][3]),
map: map,
title: 'test',
});
}
};
google.maps.event.addDomListener(window, 'load', initialize);
</script>
只需更改线下方
位置:新谷歌地图。Latlng(business_locations[i][2],business_locations[i][3])
至
位置:新谷歌地图。LatLng(business_locations[i][2],business_locations[i][3])
javascript区分大小写。它会很好用的。
在您最后一个名为Liberty的位置之后,您有一个";"-删除它。
所以应该是:
<script type="text/javascript">
function initialize()
{
var map;
var mapOptions =
{
zoom: 9,
center: new google.maps.LatLng(39.03454, -94.587315),
mapTypeId: google.maps.MapTypeId.ROADMAP,
};
map = new google.maps.Map(document.getElementById('body-space-inside'), mapOptions);
var business_locations =
[
['South Plaza', '5105 Main St Kansas City, MO 64112', '39.03454', '-94.587315'],
['City Market', '427 Main Street Kansas City, MO 64105', 39.108518, -94.582635],
['Barry Road East', '221 Northeast Barry Road Kansas City, MO 64155', 39.246116, -94.57759],
['Barry Road West', '7007 NW Barry Road Kansas City, MO 64153', 39.246116, -94.57759],
['Shawnee', '7198 Renner Road Shawnee, KS 66217', 38.999569, -94.779798],
['Blue Springs', '2201 NW State Route 7 Blue Springs, MO 64014', 39.04395, -94.271227],
['Leawood', '12920 State Line Road Leawood, KS 66209', 38.893127, -94.607991],
['Lenexa', '13400 College Boulevard Lenexa, KS 66210', 38.927529, -94.741263],
['Olathe', '15983 S Bradley Drive Olathe, KS 66062', 38.838983, -94.778771],
['Prarie Village', '6921 Tomahawk Rd Prairie Village, KS 66208', 39.003414, -94.631471],
['Independence', '2551 S State Route 291 Independence, MO 64057', 39.073201, -94.378762],
['Lees Summit', '632 NE State Route 291 Lees Summit, MO 64086', 38.923416, -94.360608],
['Liberty', '205 N 291 Highway Liberty, MO 64068', 39.246472, -94.443878]
];
for(var i = 0; i < business_locations.length; i++)
{
var marker = new google.maps.Marker({
position: new google.maps.Latlng(business_locations[i][2], business_locations[i][3]),
map: map,
title: 'test',
});
}
};
google.maps.event.addDomListener(window, 'load', initialize);
</script>
相关文章:
- Canvas Html5绘图应用程序,移动画布会导致重大问题
- HTML画布在绘图后立即擦除矩形
- 如何在JS Leatflet绘图插件中获取圆的坐标
- 在一个页面中具有多个捕捉绘图和捕捉内容
- SVG手写字母绘图动画
- 绘图悬停文本未显示
- 为画布绘图添加鼠标事件
- 如何强制绘图将x轴编号显示为类别
- 绘图应用程序-单击工具更改光标
- 重置transform:rotate(),方法是移除并追加在追加和重绘图表后未显示数据的画布
- Highcharts多个Y轴绘图带碰撞
- 如何使用画布和javascript使绘图移动
- highcharts IE8重绘图表问题
- OpenOffice绘图:增强的几何图形解析
- 如果谷歌地图绘图(如onDraw)触发什么事件
- Fabricjs在绘图时连接线条
- 高图表可拖动的绘图线与对数轴刻度
- 使用谷歌地图拍摄 Lon 和 Lan
- 如何使用 THREE.js/WebGL 将 2D 绘图转换为 3Drawing
- 谷歌地图JavaScript API V3,Lat/Lon点的绘图数组