google.maps.Polyline不是构造函数

时间:2013-04-10 22:43:51

标签: javascript google-maps

我正在尝试将PolyLine对象添加到地图中,但我收到错误消息" google.maps.Polyline不是构造函数"。对我来说这表明我没有导入这个类的定义,但我没有看到任何我在声明中遗漏的任何例子中的任何内容。我按以下方式添加了Google Maps API:

<!DOCTYPE HTML >
<html>
  <head>
    <title>
    Location: Caradoc, Middlesex, ON, CA 
    </title>
    <meta charset='utf-8'>
    <meta http-equiv='default-style' content='text/css'>
    <meta name='author' content='James A. Cobban'>
    <meta name='copyright' content='&copy; 2013 James A. Cobban'>
    <meta name='keywords' content='genealogy, family, tree, ontario, canada'>
    <link rel='stylesheet' type='text/css' href='http://localhost/styles.css'/>
    <script src='../jscripts/js20/http.js' type='text/javaScript'>
    </script>
    <script src='../jscripts/CommonForm.js' type='text/javaScript'>
    </script>
    <script src='../jscripts/util.js' type='text/javaScript'>
    </script>
    <script src='../tinymce/jscripts/tiny_mce/tiny_mce.js' type='text/javaScript'>
    </script>
    <script src='http://maps.googleapis.com/maps/api/js?sensor=false&region=CA' type='text/javaScript'>
    </script>
    <script src='LegacyLocation.js' type='text/javaScript'>
    </script>
  </head>

我一直用它来显示几年的地图。但现在我希望使用PolyLine来显示区域的边界。

var path    = [], poly;

function mapClick(mouseEvent)
{
    if (path.length == 0)
    {       // first click
    var polyOptions = {map: map,
                   strokeColor: "red", 
                   stokeOpacity: 0.5,
                   strokeWeight: 2};
    poly    = new google.maps.PolyLine(polyOptions);
    }       // first click
    path.push(mouseEvent.latLng);
    poly.setPath(path);
}

我收到错误的行直接从此网站上的一个帖子中复制。

1 个答案:

答案 0 :(得分:1)

它是new google.maps.Polyline,而不是PolyLine

具有讽刺意味的是,您可以在本文的标题中正确地将其大写,以及您引用错误消息的位置。您必须手动输入,而不是复制和粘贴...: - )

google.maps.Polyline documentation