I am new to Android, the ArcGIS Platform and ArcGIS for Android.
I need to load points (offline) from a JSON file (GeoJSON) onto the map which displays a local Tile Package (*.tpk) and shapefile.
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It only takes a minute to sign up.
Sign up to join this communityI am new to Android, the ArcGIS Platform and ArcGIS for Android.
I need to load points (offline) from a JSON file (GeoJSON) onto the map which displays a local Tile Package (*.tpk) and shapefile.
Technically we don't support shapefiles with ArcGIS Runtime SDK for Android, but it can be done. Concerning loading points from a json file you need to parse the geojson file.
// Making the request and getting the response
HttpClient client = new DefaultHttpClient();
HttpGet req = new HttpGet(url);
HttpResponse res = client.execute(req);
// Converting the response stream to string
HttpEntity jsonentity = res.getEntity();
InputStream in = jsonentity.getContent();
// string representation of json
String json_str = convertStreamToString(in);
JSONObject jsonobj = new JSONObject(json_str);
JSONArray feature_arr = jsonobj.getJSONArray("features");
// Getting the coordinates and projecting them to map's spatial
// reference
JSONObject obj_geometry = feature_arr.getJSONObject(i)
.getJSONObject("geometry");
double lon = Double.parseDouble(obj_geometry.getJSONArray("coordinates")
.get(0).toString());
double lat = Double.parseDouble(obj_geometry.getJSONArray("coordinates")
.get(1).toString());
Point point = (Point) GeometryEngine.project(
new Point(lon, lat), SpatialReference.create(4326),
mMapView.getSpatialReference());
// Add point graphic to the graphic layer
graphicsLayer.addGraphic(new Graphic(point, symbol, attr));