Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to show multiple markers on my Google map with OpenLayers. Below is my code :

for (var pointcount = 0; pointcount < jsonObj.length; pointcount++) {

if (jsonObj[pointcount].Long != null && jsonObj[pointcount].Lat != null) {

    var markerslonLat = new OpenLayers.LonLat(jsonObj[pointcount].Long, jsonObj[pointcount].Lat).transform(WGS84, map.getProjectionObject(), 0);

    markers.addMarker(new OpenLayers.Marker(markerslonLat, icon));

    alert('  marker added. Long : ' + jsonObj[pointcount].Long + '    ||    lat : ' + jsonObj[pointcount].Lat);

But, it shows only last one. What have I missed in my code?

share|improve this question

I have a feeling that your icon is being reused and that is why it appears that only the last point is showing up, it is the only one with an icon. After the icon is used once, you need to clone your icon.

so you should have something like this:

if(pointcount == 0){
    markers.addMarker(new OpenLayers.Marker(markerslonLat, icon));
    //Makes another icon to use by cloning.
    markers.addMarker(new OpenLayers.Marker(markerslonLat, icon.clone()));
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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