I have been experiencing this error for some time (as seen in Google Chrome JS Error Console):
Uncaught TypeError: Object function (value){ var i; for (i=0; i < this.length; i++) { if (this[i] == value){ return true; } } return false; } has no method 'getLatLng'
It doesn't keep the page from loading and doesn't seem to affect the performance, but it is an error so I want to fix it.
Here's the code from that page:
window.onload=load;
var isEditing = false;
var polygon = null;
var map = null;
var isCompatible = GBrowserIsCompatible();
var markers = new Array();
var iconIncluded = MapIconMaker.createLabeledMarkerIcon({addStar: false,label:"", primaryColor: "#006600"});
var iconExcluded = MapIconMaker.createLabeledMarkerIcon({addStar: false,label:"", primaryColor: "#CCCCCC"});
function editClick() {
isEditing = !isEditing;
if(isEditing && polygon != null) {
polygon.enableDrawing();
} else {
polygon.disableEditing();
}
}
// Update all markers with in poly status
function updatePoints() {
mapvoters = new Array();
for(var i in markers) {
var marker = markers[i];
var point = marker.getLatLng();
var inPoly = polygon.containsLatLng(point);
var voterid = marker.voterid;
if(inPoly) {
marker.setImage(iconIncluded.image);
Array.prototype.inArray = function (value){
var i;
for (i=0; i < this.length; i++) {
if (this[i] == value){
return true;
}
}
return false;
};
if(mapvoters.inArray(voterid)){
}else{
mapvoters.push(voterid)
}
$('#SelectedVoters').attr('value', String(mapvoters));
$('#NumSelected').html(mapvoters.length);
//$('#PolyIDs').html(String(mapvoters));
}else{
marker.setImage(iconExcluded.image);
}
}
}
function resetPolygon() {
if(polygon != null) {
map.removeOverlay(polygon);
}
polygon = new GPolygon([], "#000000", 1, 1, "#336699", 0.3);
map.addOverlay(polygon);
GEvent.addListener(polygon, "endline", function() {
setTimeout(editClick, 50);
setTimeout(updatePoints, 50);
$('#map').parents('#page_layout').find("#PolygonHelp").slideToggle(500);
GEvent.addListener(polygon, "lineupdated", function() {
setTimeout(updatePoints, 50);
});
});
}
//<![CDATA[
function load() {
if (isCompatible) {
// Create Map
map = new GMap2(document.getElementById("map"));
map.setCenter(new GLatLng(40, -90), 3);
// Add controls
map.addControl(new GLargeMapControl());
map.addControl(new GMapTypeControl());
resetPolygon();
GDownloadUrl("<?php echo $XML; ?>", function(data) {
var xml = GXml.parse(data);
var markers_xml = xml.documentElement.getElementsByTagName("marker");
var bounds = new GLatLngBounds();
for (var i = 0; i < markers_xml.length; i++) {
var listid = markers_xml[i].getAttribute("lid");
var voterid = markers_xml[i].getAttribute("voterid");
var contacted = markers_xml[i].getAttribute("contacted");
var name = markers_xml[i].getAttribute("name");
var address = markers_xml[i].getAttribute("address");
var type = markers_xml[i].getAttribute("type");
var iconcolor = markers_xml[i].getAttribute("iconcolor");
var point = new GLatLng(parseFloat(markers_xml[i].getAttribute("lat")),
parseFloat(markers_xml[i].getAttribute("lng")));
if(contacted == '2'){
var thecolor = "#CCCCCC"
}else{
var thecolor = iconcolor
}
var marker = createMarker(point, voterid, name, address, type, thecolor, listid);
map.addOverlay(marker);
bounds.extend(point);
markers.push(marker);
markers[i].voterid = voterid;
markers[i].contacted = contacted;
}
map.setZoom(map.getBoundsZoomLevel(bounds));
map.setCenter(bounds.getCenter());
});
updatePoints();
}
}
function createMarker(point, voterid, name, address, type, color, listid) {
var newIcon = MapIconMaker.createLabeledMarkerIcon({addStar: false,label:"", primaryColor: color});
var marker = new GMarker(point,{ icon: newIcon, title: name } );
var html = "<b>" + name + "</b> <br/>" + address + "<br/>" + voterid;
GEvent.addListener(marker, 'click', function() {
marker.openInfoWindowHtml(html);
});
return marker;
}
function addToWalkList(voterid){
Array.prototype.inArray = function (value){
var i;
for (i=0; i < this.length; i++) {
if (this[i] == value){
return true;
}
}
return false;
};
if(mapvoters.inArray(voterid)){
}else{
mapvoters.push(voterid)
}
}
function clearMarkers(){
$('#NumSelected').html("0");
resetPolygon();
for(var i in markers) {
var marker = markers[i];
marker.setImage(iconExcluded.image);
}
document.getElementById('edit_button').disabled = '';
editClick();
}
//]]>
</script>
I think I must be initiating the script wrongly...I'm really not sure. After several hours of research and tinkering, I turn to this community for help. Point me in the right direction. All help needed and appreciated. Thanks!