0

I have a text file that contains longitude and latitude of some items. How can i load this file onto a map?

<script src="http://openlayers.org/en/v3.0.0/build/ol.js" type="text/javascript"></script>
<script>
var attribution = new ol.control.Attribution({
                                    collapsible: false
                                });
                                var maptwo = new ol.Map({
                                    target: 'maptwo',
                                    layers: [
                                        new ol.layer.Tile({
                                            source: new ol.source.OSM()
                                        })
                                    ],
                                    controls: ol.control.defaults({attribution: false}).extend([attribution]),
                                    view: new ol.View({
                                        center: ol.proj.transform([37.41, 8.82], 'EPSG:4326', 'EPSG:3857'),
                                        zoom: 2
                                    })
                                });
</script>

                            <style>
                                .maptwo {
                                    height: 100%;
                                    width:100%;
                                }
                            </style>
2
  • 2
    IT might help to post your text data or a sample of it. By the way, your tag says OpenLayers 2 but you appear to be using version 3. Commented Dec 7, 2015 at 23:56
  • You are loading ol2 library. Then you use ol3 code to init your map, layers and controls and then you use ol2 code to init yourLocation. This should create a dozen of errors within firebug.
    – pavlos
    Commented Dec 10, 2015 at 14:24

1 Answer 1

2

You can look at this OpenLayers 3 sample I produced some time ago. It relies on the library csv2geojson.

I choose this solution because there are no native CSV support in OpenLayers 3 but GeoJSON is well supported.

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.