1

我正在尝试将 PolyLine 对象添加到地图中,但收到错误消息“google.maps.Polyline not a constructor”。对我来说,这表明我无法导入此类的定义,但我在声明中遗漏的任何示例中都看不到任何内容。我将 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>

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

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);
}

我收到错误的那一行是直接从本网站上的一篇文章复制而来的。

4

1 回答 1

2

new google.maps.Polyline,不是PolyLine

具有讽刺意味的是,你在这篇文章的标题中正确地大写了它,以及你引用错误消息的位置。您必须手动输入这些内容,而不是复制和粘贴... :-)

google.maps.Polyline 文档

于 2013-04-10T22:57:39.573 回答