Search code examples
javascriptleafletgeojson

Leafletjs - GeoJSON layer not showing


I have created a jsfiddle of the code and I don't know why the marker is not showing.

var map = L.map('map', {
    center: [8.99665, 38.81573],
    zoom: 13,
}); 

var addis = L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
        id: 'addis',
        attribution: '&copy; <a  href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
}).addTo(map);

var aa = {
    "type": "Feature",
    "properties": {
        "name": "Megenagna",
    },
    "geometry": {
        "type": "Point",
        "coordinates": [9.019720, 38.802933]
    }
};

new L.GeoJSON(aa).addTo(map);

Here is the jsfiddle url: http://jsfiddle.net/m2ju1m3v/

Please, can someone shine some light on this? Thanks!


Solution

  • Coordinates in GeoJSON are specified as an array of form [longitude, latitude], on the contrary of Leaflet where it is [latitude, longitude].

    So you should simply change your coordinates to:

    "coordinates": [38.802933, 9.019720]
    

    Updated jsfiddle: http://jsfiddle.net/m2ju1m3v/2/

    Note: please use Leaflet version 0.7.7 instead of 0.6.4.