drawing geojson line #1716
This commit is contained in:
@@ -0,0 +1 @@
|
||||
{"type":"FeatureCollection","features":[{"type":"Feature","properties":{},"geometry":{"type":"LineString","coordinates":[[-121.3714599609375,38.64583568648869],[-121.48681640624999,38.64047263931154],[-121.53076171875,38.61579745317875],[-121.56509399414061,38.57823196583313],[-121.75186157226561,38.533127435052776],[-121.97021484374999,38.35350340353833],[-122.08007812499999,38.24680876017446],[-122.16796875,38.19718009396176],[-122.23800659179686,38.09457899232253],[-122.27371215820312,38.01455819225337],[-122.33551025390625,37.94094845586459],[-122.27371215820312,37.81846319511331],[-122.4151611328125,37.7652868250379]]}}]}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -297,12 +297,12 @@ public class MainActivity extends ActionBarActivity {
|
||||
|
||||
private void addPolyline() {
|
||||
try {
|
||||
String geojsonStr = Util.loadStringFromAssets(this, "tillicum.geojson");
|
||||
String geojsonStr = Util.loadStringFromAssets(this, "small_line.geojson");
|
||||
LatLng[] latLngs = Util.parseGeoJSONCoordinates(geojsonStr);
|
||||
MapView map = mMapFragment.getMap();
|
||||
Polyline line = map.addPolyline(new PolylineOptions()
|
||||
.add(new LatLng(51.5, -0.1), new LatLng(40.7, -74.0))
|
||||
.width(5)
|
||||
.add(latLngs)
|
||||
.width(2)
|
||||
.color(Color.RED));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
|
||||
@@ -29,7 +29,9 @@ public class Util {
|
||||
|
||||
public static LatLng[] parseGeoJSONCoordinates(String geojsonStr) throws JSONException {
|
||||
JSONObject jsonObject = new JSONObject(geojsonStr);
|
||||
JSONObject geometry = jsonObject.getJSONObject("geometry");
|
||||
JSONArray features = jsonObject.getJSONArray("features");
|
||||
JSONObject feature = features.getJSONObject(0);
|
||||
JSONObject geometry = feature.getJSONObject("geometry");
|
||||
JSONArray coordinates = geometry.getJSONArray("coordinates");
|
||||
int len = coordinates.length();
|
||||
LatLng[] latLngs = new LatLng[coordinates.length()];
|
||||
|
||||
Reference in New Issue
Block a user