Skip to content Skip to sidebar Skip to footer

Uncaught Typeerror: Object # Has No Method 'getposition'

I'm trying to display the visible markers in a map and can 't get this code to work. In the console it displays the marker information like I expect.
var gmarkers = []; // in the global scope

function showVisibleMarkers() {
   for (var i = 0; i < gmarkers.length; i++) {
     // console.log(markers[i]);
     if (map.getBounds().contains(gmarkers[i].getPosition())) {
       // code to display markers
     }
   }
}

function displaymap(lat, lng, state, min, max) {
    map = new google.maps.Map(document.getElementById("mapdiv"), {
      center: new google.maps.LatLng(lat, lng),
      zoom: 7,
      mapTypeId: 'roadmap',
      panControl: true,
      zoomControl: true,
      streetViewControl: true,
      mapTypeControl: true
    });

    var infoWindow = new google.maps.InfoWindow;
    // Change this depending on the name of your PHP file
    downloadUrl("/inc/db_query.php?lat=" + lat + "&lng=" + lng + "&state=" + state + "&min=" + min + "&max=" + max, function(data) {
      var xml = data.responseXML;
      var bounds = new google.maps.LatLngBounds();
      markers = xml.documentElement.getElementsByTagName("marker");
      for (var i = 0; i < markers.length; i++) {
        var name = markers[i].getAttribute("name");
        var address = markers[i].getAttribute("address");
        if (markers[i].getAttribute("daily") === '') {
          var icon = '/img/blackdot.png';
        } else if (markers[i].getAttribute("daily") === 0) {
          var icon = '/img/greendot.png';
        } else if (markers[i].getAttribute("daily") > 0 && markers[i].getAttribute("daily") < 10) {
          var icon = '/img/bluedot.png';
        } else if (markers[i].getAttribute("daily") > 9 && markers[i].getAttribute("daily") < 20) {
          var icon = '/img/purpledot.png';
        } else if (markers[i].getAttribute("daily") > 19 && markers[i].getAttribute("daily") < 30) {
          var icon = '/img/reddot.png';
        } else if (markers[i].getAttribute("daily") > 29 && markers[i].getAttribute("daily") < 40) {
          var icon = '/img/orangedot.png';
        } else if (markers[i].getAttribute("daily") > 39 && markers[i].getAttribute("daily") < 50) {
          var icon = '/img/yellowdot.png';
        } else if (markers[i].getAttribute("daily") > 49) {
          var icon = '/img/whitedot.png';
        }
        var position = new google.maps.LatLng(
                parseFloat(markers[i].getAttribute("lat")),
                parseFloat(markers[i].getAttribute("lng")));
        var html = "<b>" + name + "</b> <br/>" + address;
        var marker = new google.maps.Marker({
          map: map,
          position: position,
          icon: icon
        });
        gmarkers.push(marker); // <---------------------------- add this line.
        bindInfoWindow(marker, map, infoWindow, html);
        bounds.extend(position);
        map.fitBounds(bounds);
      }
    });
    google.maps.event.addListener(map, 'idle', function() {
      showVisibleMarkers();
    });
  }

Post a Comment for "Uncaught Typeerror: Object # Has No Method 'getposition'"