2

Im looking for a way to add a marker on a position that is not in a database using cartodb.js.

Something similar to this in Mapbox would be great:

L.mapbox.featureLayer({
    // this feature is in the GeoJSON format: see geojson.org
    // for the full specification
    type: 'Feature',
    geometry: {
        type: 'Point',
        // coordinates here are in longitude, latitude order because
        // x, y is the standard for GeoJSON and many formats
        coordinates: [
          -77.03221142292,
          38.913371603574 
        ]
    },
1

You can use Leaflet for this, an example:

cartodb.createVis('map', VIZ_JSON_HERE)
        .done(function(vis, layers) {
          map = vis.getNativeMap();
          L.marker([51.5, -0.09]).addTo(map);
        })
        .error(function(err) {
          console.log(err);
        });

The Leaflet library is included directly when you include CartoDB.js, so you won't need to worry about that :-)

If you're interested on how to customize those markers I recommend you to take a look here: http://leafletjs.com/examples/custom-icons.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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