I am trying to show a geojson layer for google map. The code is as follows. The geojson file is stored locally in my source folder. The file has 286 functions (about 15 MB). Therefore, reading this file and displaying it consumes more time. Initially, I had a memory error that is deleted by setting the big heap as true in the manifest file. How to quickly download this file (it currently takes a minute or more)? I am wondering if there is another effective method for this. After that, I will also have other tasks of getting functions and displaying some properties.
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map); mapFragment.getMapAsync(this); } @Override public void onMapReady(GoogleMap googleMap) { mMap = googleMap; mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(myanmar, 5.25f)); new MyAsyncTask().execute(); } public class MyAsyncTask extends AsyncTask <Void, Void, Void> { ProgressDialog pd; GeoJsonLayer layer; @Override protected void onPreExecute() { super.onPreExecute(); pd = new ProgressDialog(MapsActivity.this); pd.setMessage("Loading Data"); pd.show(); } @Override protected Void doInBackground(Void... voids) { try { layer = new GeoJsonLayer(mMap, R.raw.myanmar, getApplicationContext()); } catch (Exception e) { Log.d("Error is : ", e.toString()); } return null; } @Override protected void onPostExecute(Void aVoid) { super.onPostExecute(aVoid); pd.cancel(); layer.addLayerToMap(); } }
A very small part of my geojson file looks like this:
{ "type": "FeatureCollection", "crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:OGC:1.3:CRS84" } }, "features": [ { "type": "Feature", "properties": { "ID_3": 193, "NAME_3": "Chaung-U" }, "geometry": { "type": "MultiPolygon", "coordinates": [ [ [ [ 95.348327636718807, 21.878610610961914 ], [ 95.297210693359432, 21.860000610351676 ], [ 95.286926269531307, 21.853612899780387 ], [ 95.276092529296989, 21.850000381469727 ], [ 95.265823364257926, 21.84832954406744 ], [ 95.257217407226676, 21.846940994262695 ] ] ] ] } }, { "type": "Feature", "properties": { "ID_3": 199, "NAME_3": "Myaung" }, "geometry": { "type": "MultiPolygon", "coordinates": [ [ [ [ 95.376281738281193, 21.708541870117301 ], [ 95.375259399414119, 21.703050613403434 ], [ 95.370529174804801, 21.681390762329102 ], [ 95.367752075195313, 21.664720535278434 ], [ 95.366699218750114, 21.658369064331055 ], [ 95.362762451171875, 21.649999618530273 ] ] ] ] } } ]}
I am trying to split a file into several small file blocks and run separate async tasks in parallel, each processes a separate file:
for (int i = 1; i < 3; i++) { new MyAsyncTask().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR,i); }
AsyncTask:
public class MyAsyncTask extends AsyncTask <Integer, Void, GeoJsonLayer> { @Override protected void onPreExecute() { super.onPreExecute(); } @Override protected GeoJsonLayer doInBackground(Integer... integers) { int i = integers[0]; try { GeoJsonLayer layer = null; switch (i) { case 1: layer = new GeoJsonLayer(mMap, R.raw.small_1, getApplicationContext()); break; case 2: layer = new GeoJsonLayer(mMap, R.raw.small_2, getApplicationContext()); break;
Is this an offer? At the same time, it decreases compared to the previous one, but still does not take into account the user experience coefficient very quickly.