JSON data is common and useful in Android, and JSON data is also supported in ArcGIS, and JSON and geometry can be converted to the data we want.
One, geometry converted to JSON data
This implementation is very simple, for example, when we convert a point to JSON, we also use the powerful class Geometryengine.
Point point = new Point(113, 23); String json = GeometryEngine.geometryToJson(SpatialReference.create(SpatialReference.WKID_WGS84), point); Log.w("TAG", "json===" + json);
The result of printing log is json==={"x":113.0,"y":23.0,"spatialReference":{"wkid":4326}}
, is not very simple.
Second, JSON converted to geometry
We also use the Jsontogeometry method in the Geometryengine class, and we convert the above JSON back.
try {String jsonstr ="{\" x\ ": 113.0,\" y\ ": 23.0,\" spatialreference\ ": {\" wkid\ ": 4326}}"; Jsonfactory jsonfactory = new Jsonfactory (); Jsonparser Jsonparser = jsonfactory. Createjsonparser (JSONSTR); Mapgeometry mapgeometry = Geometryengine. Jsontogeometry (Jsonparser); Point mpoint = (point) mapgeometry. Getgeometry (); Log. I ("TAG", "mpoint---" +mpoint. GetX () +"= = =" +mpoint. GetY ())} catch (IOException e) {e. Printstacktrace ();}
The result of the code execution mPoint---113.0===23.0
. Note: Jsonfactory.createjsonparser This method can be brought into the parameters are also more, such as: File, OutputStream, byte array and so on, interested in small partners can study.
Android GIS Development Series-Introductory season (8) JSON-to-geometry conversion