0

I have a problem for displaying data to info windows on the Google Maps Data layer. Here I use GeoJSON to load data. can anyone help me?

var map;
function initMap() {
  map = new google.maps.Map(document.getElementById('map'), {
    zoom: 4,
    center: {lat: -2.9365327, lng: 104.4950964}
  });

  map.data.loadGeoJson(
    'https://d2ad6b4ur7yvpq.cloudfront.net/naturalearth-3.3.0/ne_50m_rivers_lake_centerlines.geojson');
  console.log( map.data);

 var ced = google.maps.event.addListener(map.data,'click',function(event) {       
    console.log(event.feature.f)
    alert("Koordinat:lat: "+event.latLng.lat()+", lng: "+event.latLng.lng());
    alert(JSON.stringify(event.feature.f));
  });
}

At this moment I'm just can make data appear on alert method.

enter image description here

enter image description here

And I want to make the data show from info windows when that street was clicked.

0

You are almost there. You just have to use the getProperty method of the returned Feature object. See below:

var ced = google.maps.event.addListener(map.data,'click',function(event) {       
   console.log(event.feature.getProperty('name'))
   alert("Koordinat:lat: "+event.latLng.lat()+", lng: "+event.latLng.lng());
   alert(event.feature.getProperty('name'));
});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.