I managed to add cards to my map overlay, but it slowly loads, and moving around the map is listless. I think this is when he downloads maps from the server. The pins have a size of about 20-30 kb, but sometimes 25 pins can be added. I already tried adding pins in the background, but this will break the application. What can be done to add contacts in the background without affecting performance?
I get the location from the map when the user touches the map and performs this ASYNC task.
private class mapStations extends AsyncTask<Void, Void, JSONObject> { @Override protected JSONObject doInBackground(Void... arg0) { JSONObject obj = null; try { obj = new JSONObject(API.nearByStations(pxLat, pxLng, 0)); } catch (JSONException e) { e.printStackTrace(); } return obj; } @Override protected void onPostExecute(JSONObject details) { String tag = "mapStations"; JSONArray stations; Drawable d = null; try { mapOverlays = mapView.getOverlays(); mapOverlays.clear(); stations = details.getJSONArray("stations"); for (int j = 0; j < stations.length(); j++) { JSONObject jsonObject = stations.getJSONObject(j); Log.i(tag, "url: " + jsonObject.getString("logo")); try { Bitmap staticImage = BitmapFactory .decodeStream((InputStream) new URL(jsonObject.getString("logo")) .getContent()); d = new BitmapDrawable(staticImage); } catch (MalformedURLException e) { Log.e(tag, e.toString()); e.printStackTrace(); } catch (IOException e) { Log.e(tag, e.toString()); e.printStackTrace(); } add(jsonObject.getDouble("lat"), jsonObject.getDouble("lng"), d); } } catch (JSONException e) { e.printStackTrace(); } } } public void add(double lat, double lng, Drawable d) { mapOverlays = mapView.getOverlays(); if(d.equals(null)){ Log.i(tag, "d was null"); d = this.getResources().getDrawable(R.drawable.androidmarker); } itemizedOverlay = new MapsOverlay(d); GeoPoint point = new GeoPoint((int) (lat * 1e6), (int) (lng * 1e6)); OverlayItem overlayitem = new OverlayItem(point, "", ""); itemizedOverlay.addOverlay(overlayitem); mapOverlays.add(itemizedOverlay); }
This is the trap of adding points to the doinbackground. This does not happen every time, but it happens. I can't seem to reproduce when that happens. Sometimes it happens when I zoom out, sometimes it happens when I move around the map. I had a similar question about this here Android MapView JSON Array Adding an array of points , but I moved it to post execute. As I mentioned earlier, it will take some time to download contacts. I kind of can't write. I have been working on this all day.
[12-23 13:46:27.246: E/AndroidRuntime(1359): Uncaught handler: thread main exiting due to uncaught exception 12-23 13:46:27.286: E/AndroidRuntime(1359): java.util.ConcurrentModificationException 12-23 13:46:27.286: E/AndroidRuntime(1359): at java.util.AbstractList$SimpleListIterator.next(AbstractList.java:64) 12-23 13:46:27.286: E/AndroidRuntime(1359): at com.google.android.maps.OverlayBundle.draw(OverlayBundle.java:41) 12-23 13:46:27.286: E/AndroidRuntime(1359): at com.google.android.maps.MapView.onDraw(MapView.java:476) 12-23 13:46:27.286: E/AndroidRuntime(1359): at android.view.View.draw(View.java:6535) 12-23 13:46:27.286: E/AndroidRuntime(1359): at android.view.ViewGroup.drawChild(ViewGroup.java:1531) 12-23 13:46:27.286: E/AndroidRuntime(1359): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1258) 12-23 13:46:27.286: E/AndroidRuntime(1359): at android.view.ViewGroup.drawChild(ViewGroup.java:1529) 12-23 13:46:27.286: E/AndroidRuntime(1359): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1258) 12-23 13:46:27.286: E/AndroidRuntime(1359): at android.view.View.draw(View.java:6538) 12-23 13:46:27.286: E/AndroidRuntime(1359): at android.widget.FrameLayout.draw(FrameLayout.java:352) 12-23 13:46:27.286: E/AndroidRuntime(1359): at android.view.ViewGroup.drawChild(ViewGroup.java:1531) 12-23 13:46:27.286: E/AndroidRuntime(1359): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1258) 12-23 13:46:27.286: E/AndroidRuntime(1359): at android.view.ViewGroup.drawChild(ViewGroup.java:1529) 12-23 13:46:27.286: E/AndroidRuntime(1359): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1258) 12-23 13:46:27.286: E/AndroidRuntime(1359): at android.view.ViewGroup.drawChild(ViewGroup.java:1529) 12-23 13:46:27.286: E/AndroidRuntime(1359): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1258) 12-23 13:46:27.286: E/AndroidRuntime(1359): at android.view.ViewGroup.drawChild(ViewGroup.java:1529) 12-23 13:46:27.286: E/AndroidRuntime(1359): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1258) 12-23 13:46:27.286: E/AndroidRuntime(1359): at android.view.ViewGroup.drawChild(ViewGroup.java:1529) 12-23 13:46:27.286: E/AndroidRuntime(1359): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1258) 12-23 13:46:27.286: E/AndroidRuntime(1359): at android.view.View.draw(View.java:6538) 12-23 13:46:27.286: E/AndroidRuntime(1359): at android.widget.FrameLayout.draw(FrameLayout.java:352)][1] 12-23 13:46:27.286: E/AndroidRuntime(1359): at android.view.ViewGroup.drawChild(ViewGroup.java:1531) 12-23 13:46:27.286: E/AndroidRuntime(1359): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1258) 12-23 13:46:27.286: E/AndroidRuntime(1359): at android.view.ViewGroup.drawChild(ViewGroup.java:1529) 12-23 13:46:27.286: E/AndroidRuntime(1359): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1258) 12-23 13:46:27.286: E/AndroidRuntime(1359): at android.view.View.draw(View.java:6538) 12-23 13:46:27.286: E/AndroidRuntime(1359): at android.widget.FrameLayout.draw(FrameLayout.java:352) 12-23 13:46:27.286: E/AndroidRuntime(1359): at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:1830) 12-23 13:46:27.286: E/AndroidRuntime(1359): at android.view.ViewRoot.draw(ViewRoot.java:1349) 12-23 13:46:27.286: E/AndroidRuntime(1359): at android.view.ViewRoot.performTraversals(ViewRoot.java:1114) 12-23 13:46:27.286: E/AndroidRuntime(1359): at android.view.ViewRoot.handleMessage(ViewRoot.java:1633) 12-23 13:46:27.286: E/AndroidRuntime(1359): at android.os.Handler.dispatchMessage(Handler.java:99) 12-23 13:46:27.286: E/AndroidRuntime(1359): at android.os.Looper.loop(Looper.java:123) 12-23 13:46:27.286: E/AndroidRuntime(1359): at android.app.ActivityThread.main(ActivityThread.java:4363) 12-23 13:46:27.286: E/AndroidRuntime(1359): at java.lang.reflect.Method.invokeNative(Native Method) 12-23 13:46:27.286: E/AndroidRuntime(1359): at java.lang.reflect.Method.invoke(Method.java:521) 12-23 13:46:27.286: E/AndroidRuntime(1359): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860) 12-23 13:46:27.286: E/AndroidRuntime(1359): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618) 12-23 13:46:27.286: E/AndroidRuntime(1359): at dalvik.system.NativeStart.main(Native Method)
Brandon wilson
source share