Reputation: 2211
I keep getting message: "Invalid GeoJSON"
errors when trying to add a polygon to a static map on mapbox api.
On the following map:
My LineString example works to outline the border of the polygon I wish to draw:
geojson({"type":"Feature","properties":{},"geometry":{"type":"LineString","coordinates":[[-120.8492,39.4916],[-120.8474,39.4896],[-120.8510,39.4864],[-120.8492,39.4916]]}})
If try to turn it into a polygon using the following geojson object:
geojson({"type":"Feature","properties":{},"geometry":{"type":"Polygon","coordinates":[[-120.8492,39.4916],[-120.8474,39.4896],[-120.8510,39.4864],[-120.8492,39.4916]]}})
It blows up:
Can anybody see what I am doing wrong? I'm having problems finding any examples of using the static api to draw polygons but the static api doc says that this is possible.
Thanks.
Upvotes: 2
Views: 2025
Reputation: 86
Your geojson
string is not valid. You've missed two square brackets around the coordinates. Here's a valid formula.
geojson({
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [[[-120.8492, 39.4916], [-120.8474, 39.4896], [-120.8510, 39.4864], [-120.8492, 39.4916]]]
}
})
If you want to generate a static map with your polygon, the corresponding API call would something like
You can try it on this website http://staticmapmaker.com/mapbox/
Upvotes: 7
Reputation: 2211
I couldn't work out how to do this using geojson but realised that I could do this with polylines and the fill property.
I calculated my polylines with help from the google maps for android polyutil class.
Upvotes: 1