Google Maps JavaScript API V3,绘制Lat/Lon点的数组

Google Maps JavaScript API V3,绘制Lat/Lon点的数组,javascript,google-maps,Javascript,Google Maps,我正在尝试创建一个简单的谷歌地图,它将遍历一个由Lat/Lon对组成的多维数组并绘制它们。如果注释掉for循环,则将显示映射。提前谢谢 以下是我的代码: <script type="text/javascript"> function initialize() { var map; var mapOptions = { zoom: 9, center: new google.maps.LatLng(

我正在尝试创建一个简单的谷歌地图,它将遍历一个由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>

函数初始化()
{       
var映射;
var映射选项=
{
缩放:9,
中心:新google.maps.LatLng(39.03454,-94.587315),
mapTypeId:google.maps.mapTypeId.ROADMAP,
};
map=new google.maps.map(document.getElementById('body-space-inside'),mapOptions);
var业务单元位置=
[
[“南广场”,“密苏里州堪萨斯城缅因街5105号,邮编64112”,“39.03454”,“94.587315”],
[City Market',美国密苏里州堪萨斯城大街427号64105',39.108518,-94.582635],
['Barry Road East','221东北部Barry Road Kansas City,MO 64155',39.246116,-94.57759],
[美国密苏里州堪萨斯城巴里路西北7007号,邮编64153',39.246116,-94.57759],
['Shawnee','7198雷纳路Shawnee,KS 66217',38.999569,-94.779798],
['Blue Springs','2201西北州7号线,密苏里州Blue Springs 64014',39.04395,-94.271227],
[Leawood',肯塔基州利伍德国道12920号,邮编66209',38.893127,-94.607991],
['Lenexa','13400学院大道Lenexa,KS 66210',38.927529,-94.741263],
[奥拉特,堪萨斯州奥拉特布拉德利大道南15983号,邮编66062',38.838983,-94.778771],
['Prarie村','6921战斧路大草原村,KS 66208',39.003414,-94.631471],
[独立','2551 S国道291号独立,密苏里州64057',39.073201,-94.378762],
['Lees Summit','632 NE国道291号Lees Summit,密苏里州64086',38.923416,-94.360608],
['Liberty','205 N 291高速公路Liberty,密苏里州64068',39.246472,-94.443878];
];
对于(变量i=0;i
在上一个名为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>

函数初始化()
{       
var映射;
var映射选项=
{
缩放:9,
中心:新google.maps.LatLng(39.03454,-94.587315),
mapTypeId:google.maps.mapTypeId.ROADMAP,
};
map=new google.maps.map(document.getElementById('body-space-inside'),mapOptions);
var业务单元位置=
[
[“南广场”,“密苏里州堪萨斯城缅因街5105号,邮编64112”,“39.03454”,“94.587315”],
[City Market',美国密苏里州堪萨斯城大街427号64105',39.108518,-94.582635],
['Barry Road East','221东北部Barry Road Kansas City,MO 64155',39.246116,-94.57759],
[美国密苏里州堪萨斯城巴里路西北7007号,邮编64153',39.246116,-94.57759],
['Shawnee','7198雷纳路Shawnee,KS 66217',38.999569,-94.779798],
['Blue Springs','2201西北州7号线,密苏里州Blue Springs 64014',39.04395,-94.271227],
[Leawood',肯塔基州利伍德国道12920号,邮编66209',38.893127,-94.607991],
['Lenexa','13400学院大道Lenexa,KS 66210',38.927529,-94.741263],
[奥拉特,堪萨斯州奥拉特布拉德利大道南15983号,邮编66062',38.838983,-94.778771],
['Prarie村','6921战斧路大草原村,KS 66208',39.003414,-94.631471],
[独立','2551 S国道291号独立,密苏里州64057',39.073201,-94.378762],
['Lees Summit','632 NE国道291号Lees Summit,密苏里州64086',38.923416,-94.360608],
['Liberty','205 N 291公路自由,密苏里州64068',39.246472,-94.443878]
];
对于(变量i=0;i
只需在第行下方更改即可

职位:新建google.maps.Latlng(商务地点[i][2],商务地点[i][3])

职位:新建google.maps.LatLng(商务地点[i][2],商务地点[i][3])


javascript区分大小写。它可以正常工作。

检查您的javascript错误。除了错误的“;”,还有相当明显的
google.maps.Latlng不是构造函数(javascript区分大小写,名称应为google.maps.Latlng,两个“L”都是大写)