Reputation: 11
I am trying to add a PolyLine object to a map but I am getting the error message " google.maps.Polyline not a constructor". To me this indicates that I am failing to import the definition of this class, but I do not see anything in any of the examples of anything I am missing from the declaration. I am including the Google Maps API as follows:
<!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='© 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®ion=CA' type='text/javaScript'>
</script>
<script src='LegacyLocation.js' type='text/javaScript'>
</script>
</head>
I have been using this to display a map for a couple of years now. But now I wish to use a PolyLine to display the borders of a region.
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);
}
The line I am getting the error on is copied directly from one of the posts on this site.
Upvotes: 1
Views: 1805
Reputation: 28870
It's new google.maps.Polyline
, not PolyLine
.
Ironically, you have it capitalized correctly in the title of this post, as well as where you cited the error message. You must have typed those in by hand instead of copying and pasting... :-)
google.maps.Polyline documentation
Upvotes: 2