Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Leaflet Markers

I’m new to leaflet, and I’m trying to display the markers. The tutorials don’t seem to work for me. The map shows up fine, however I just can’t get a marker to display. below is my sample code:

wax.tilejson('http://localhost:8888/v2/DigitalHumanities.json',
  function(tilejson) {
        var map = new L.Map('map-div')
            .addLayer(new wax.leaf.connector(tilejson))
            .setView(new L.LatLng(-17.1828,137.4609), 4);

    var markers = new L.marker(-17.1828,137.4609);
    map.addLayer(markers);

    var markerx = new L.marker(137.4609,-17.1828);
    map.addLayer(markerx);

  });

I’ve tried the samples in the tutorials i.e.: .addTo(map); , map.addLayer(markers); etc.

like image 972
Zain Avatar asked Feb 15 '13 02:02

Zain


2 Answers

The L.marker constructor should be used as:

var markers = L.marker([-17.1828,137.4609]);
map.addLayer(markers);

You can check the API reference here

like image 186
psousa Avatar answered Sep 23 '22 01:09

psousa


The actual syntax for creating leaflet marker is

L.marker(<LatLng> latlng, <Marker options> options? );

You can check the API reference here
Below is your code

correct code

wax.tilejson('http://localhost:8888/v2/DigitalHumanities.json',
  function(tilejson) {
        var map = new L.Map('map-div')
            .addLayer(new wax.leaf.connector(tilejson))
            .setView(new L.LatLng(-17.1828,137.4609), 4);

    var markers = new L.marker([-17.1828,137.4609],{clickable:true});
    map.addLayer(markers);

    var markerx = new L.marker([137.4609,-17.1828]);
    map.addLayer(markerx);

  });
like image 34
Nikhil Sharma Avatar answered Sep 24 '22 01:09

Nikhil Sharma