ArcGIS Android app client loads business data in JSON format

Source: Internet
Author: User
1 Overview

Sometimes we need to store business data on mobile devices to ensure that the data is accessible offline. There are many ways to store offline data. This article describes how to store business data through JSON files, and then read and draw data on the android client.

2. Prepare a JSON File

First, you need to prepare a JSON file. In this example, I have published business data to the map service. Therefore, we can use the element query method of the ArcGIS rest service to obtain data in JSON format.

Is the service layer used for testing:


Find the "query" button at the bottom of the "Education and Scientific Research _ point_wm" layer page in the "Beijing" map service, for example:


Click the query button to go to the element query page, for example:


Here, you can set query filtering conditions as needed. This article sets the constant condition "1 = 1" to obtain all elements, set the output field to all fields, and return element ry, in addition, you must set the format of the returned result to JSON, for example:


After setting the query conditions and return parameters, click a query button to obtain the element set in JSON format that meets the conditions, for example:


Copy all the content, create a new text file, paste the content, and save the file in features. JSON format, such:


Now the business data of the JSON file is ready and uploaded to the Android mobile phone or tablet for reading.

3. Android client reading

Because ArcGIS Android SDK provides on-site calling interfaces, the client only needs several linesCodeYou can load the JSON file and draw it out in graphic. The key code is as follows:

Jsonfactory factory = new jsonfactory (); Uri uri = new uri ("file: // MNT/sdcard/basemap/Beijing/poi/features2.json "); file file = new file (URI); jsonparser = factory. createjsonparser (New fileinputstream (File); featureset features = featureset. fromjson (jsonparser); graphic [] graphics = features. getgraphics (); graphicslayer poi = new graphicslayer (); simplemarkersymbol sym = new simplemarkersymbol (color. blue, 8, simplemarkersymbol. style. circle); simplerenderer Renderer = new simplerenderer (sym); poi. setrenderer (Renderer); poi. addgraphics (graphics); map. addlayer (POI );

With the above code, you can load the element set in the JSON file to the graphicslayer, but the following error is reported during actual operation:

Analysis found that the original encoding format problems, need to save the JSON file as the UTF-8 format, so the features. JSON save another, such:


Save the file and upload it to your mobile phone or tablet. Then, test the result as follows:


The Blue Points on the graph are the business data in JSON format loaded and can be used for subsequent query and analysis operations.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.