I am making my way through learning Mapbox and Mapbox.js. I have loaded my GeoJSON data from a URL:

var featureLayer = L.mapbox.featureLayer()

Now I am trying to parse out the lat and lon coordinates. It makes sense to me to try something like:

var longitude = featureLayer.geometry.coordinates[0];
var latitude = featureLayer.geometry.coordinates[1];

but that is not right.

Should I be using the feature layer or the GeoJSON layer for this?


1 Answer 1


L.mapbox.featureLayer() has a getGeoJSON method. For the first feature in the GeoJSON FeatureCollection:

var longitude = (featureLayer.getGeoJSON()).features[0].geometry.coordinates[0];
var latitude = (featureLayer.getGeoJSON()).features[0].geometry.coordinates[1];

Your Answer

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

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