Adding google.maps.latlng within a loop
- by Mick Morrison
I am new to Java Script. I am using it, in combination with Java Server Faces.
I want to add some points to define a Polilyne using GoogleMaps Apiv3. My problem is that I can't add a FOR statement to the javascript, because it dumps. If I comment this FOR loop, it also dumps. The dump I am getting is: "javax.servlet.ServletException: null source".
Has anyone any suggestion to solve this? Thanks in advance, Emanuel
<script type="text/javascript">
function initialize()
{
var longit = "${dateRange.longitude}" ;
var lat = "${dateRange.latitude}" ;
var latlng = new google.maps.LatLng(lat, longit);
var myOptions =
{
zoom: 15,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
var points = [];
var cadena1 = "${dateRange.latArray}" ;
var cadena2 = "${dateRange.longArray}" ;
var latArray = cadena1.split('?');
var longArray = cadena2.split('?');
/* The code Below is the one that fails */
for (var i=0; i < latArray.length; i++)
{
points.push(new google.maps.LatLng(latArray[i], longArray[i]));
}
/* Finish of the error code */
// The Polilyne is created
var mapPath = new google.maps.Polyline
({
path: points,
strokeColor: "#FF0000",
strokeOpacity: 1.0,
strokeWeight: 4
});
mapPath.setMap(map);
}
</script>
</head>
<body onload="initialize()">
<h:graphicImage url="http://localhost:8080/gps_tracking/faces/resources/images/logo.jpg">
</h:graphicImage>
<h1 align="center">Sol-Tech</h1><br />
<hr></hr>
<div id="map_canvas" style="width:100%; height:100%"></div>
</body>