Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Map KML layer - click event return ZERO_RESULTS

I am working with the Google Maps KML layer click event.

I am using this code:

function initialize() {
  var mapOptions = {
    center: new google.maps.LatLng(41.875696, -87.624207),
    zoom: 11,
    mapTypeId: google.maps.MapTypeId.ROADMAP
  };

  var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);

  var ctaLayer = new google.maps.KmlLayer('https://sites.google.com/site/anoopkml123/kml/ab9Plan0520.kmz');

  ctaLayer.setMap(map);

  google.maps.event.addListener(ctaLayer, 'click', function(kmlEvent) {
    alert(kmlEvent.featureData.name);
  });
}

Sometimes alert(kmlEvent.featureData.name) shows a number but sometimes it's 'undefined'. Sometimes obj.featuredData.id is null (ZERO_RESULTS status is in status field).

like image 377
Sudha Avatar asked Jan 22 '13 09:01

Sudha


1 Answers

Re-created your code in a fiddle: http://jsfiddle.net/mdares/TAfys/

I cannot replicate the issue you are having. Can you provide an example given the above link of where it fails? Is this possibly browser specific? Finally - is there any additional code you haven't posted which might be the cause? My code is unchanged from yours as you posted, but I am curious if you are also doing other things:

function initialize() {
var mapOptions = {
    center: new google.maps.LatLng(41.875696, -87.624207),
    zoom: 11,
    mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);

var ctaLayer = new google.maps.KmlLayer('https://sites.google.com/site/anoopkml123/kml/ab9Plan0520.kmz');
ctaLayer.setMap(map);
google.maps.event.addListener(ctaLayer, 'click', function (kmlEvent) {
    alert(kmlEvent.featureData.name);
   });
}
like image 68
Matthew Avatar answered Oct 10 '22 08:10

Matthew