1

The geoJSON-String:

{
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "properties": {"title": "Standort 1 "},
      "geometry": {
        "type": "Point",
        "coordinates": [
          13.444175720214844,
          52.580522509085554
        ]
      }
    }
    ,...
  ]
}

This is my code to read and create the features to markers in openlayers:

var geo = new OpenLayers.Format.GeoJSON();

var obj = JSON.parse(featureJson);
var features = geo.read(obj, "FeatureCollection");

alert(features[0].attributes.length);

This works fine and I'm able to create the markers.

But what am I missing on this line?

for(var i=0;i < features.length;i++) {
    alert(features[i].attributes.title);
}

The output = "undefined".

2

I think you should have

for(var i=0;i < features.length;i++) {
alert(features[i].attributes.title);
}

Not

for(var i=0;i < features.length;i++) {
alert(attributes[i].attributes.title);
}
1
  • You are right...sorry just an error in my post. But the code isnt working... – user2463728 Oct 12 '13 at 7:45

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.