0

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.

2
  • The following tread on ArcGIS Resources forms discuss how to bring in GeoJSON into ArcGIS Runtime SDK for Android: forums.arcgis.com/threads/… Jun 26 '14 at 13:24
  • it's not what i want. I need the Code to Load a point or point from a JSON file.
    – The Coder
    Jun 30 '14 at 6:50
0

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));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.