0

Using OpenLayers, I want to display multiple markers over an OSM map by creating them from an array within a while loop.

The code works when I hard-code a single coordinate, but not when reading the coordinates from the array.

What can be done to construct the markers?

JSFiddle: http://jsfiddle.net/qmxrtnfo/9/

You can test it via:

ol.proj.fromLonLat([lonlatarray[i]]) 
//  ol.proj.fromLonLat([16.332253, 48.503684])

1 Answer 1

3

You can declare your coordinates as 2D array of numeric values.:

var lonlatarray = [
[16.332253, 48.503684],
[16.432503, 48.565917],
[16.402290, 48.473580]
];

You can then call each coordinates in the loop using

ol.proj.fromLonLat(lonlatarray[i])

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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