Answer the question
In order to leave comments, you need to log in
Am I formatting the JSON object incorrectly?
var y =
{
"type":"Point","coordinates":[31.5,42.2],"bbox":[31.5,42.2,31.5,42.2]
}
L.geoJSON(y).addTo(Window.map);
var x = JSON.stringify(geojson);
L.geoJSON(x).addTo(Window.map);
Answer the question
In order to leave comments, you need to log in
JSON.strinfigy serializes a JavaScript object into a string. For example, to transfer somewhere.
geoJSON(x), in turn, wants to get just a JavaScript object as an argument, and not its string representation, which you palm off on it.
Therefore, the first option works for you, because y is not a JSON object, it is a JavaScript Object. It will become a JSON object only when you serialize it via JSON.stringify
Therefore, the first option works for you - you feed the JS object.
And the second one does not work - for some reason you turn the JS object into a string and feed the string already, although you need this geojson itself
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question