yay, polygon! #1716

This commit is contained in:
Nicholas Hallahan
2015-07-16 18:04:46 -07:00
parent e84e13a85a
commit e1cdc8209c
2 changed files with 8 additions and 2 deletions

View File

@@ -317,7 +317,7 @@ public class MainActivity extends ActionBarActivity {
private void addPolygon() {
String geojsonStr = null;
try {
geojsonStr = Util.loadStringFromAssets(this, "small_polygon.geojson");
geojsonStr = Util.loadStringFromAssets(this, "small_poly.geojson");
LatLng[] latLngs = Util.parseGeoJSONCoordinates(geojsonStr);
MapView map = mMapFragment.getMap();
Polygon polygon = map.addPolygon(new PolygonOptions()

View File

@@ -32,7 +32,13 @@ public class Util {
JSONArray features = jsonObject.getJSONArray("features");
JSONObject feature = features.getJSONObject(0);
JSONObject geometry = feature.getJSONObject("geometry");
JSONArray coordinates = geometry.getJSONArray("coordinates");
String type = geometry.getString("type");
JSONArray coordinates;
if (type.equals("Polygon")) {
coordinates = geometry.getJSONArray("coordinates").getJSONArray(0);
} else {
coordinates = geometry.getJSONArray("coordinates");
}
int len = coordinates.length();
LatLng[] latLngs = new LatLng[coordinates.length()];
for (int i = 0; i < len; ++i) {