Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6953007
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:25:21+00:00 2026-05-27T14:25:21+00:00

I am creating a map application that receives a list of coords from a

  • 0

I am creating a map application that receives a list of coords from a JSON array. I @Override dispatchTouchEvent to find the coords from the map and then execute an ASYNCTask to get the new points.

It loads the points but after scrolling around it force closes. What would be ideal is to clear the current points on the map and reload new points from a new location after the touch event.

Here is my code so far:

@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
    int actionType = ev.getAction();
    switch (actionType) {
    case MotionEvent.ACTION_UP:
        Projection proj = mapView.getProjection();
        GeoPoint loc = proj.fromPixels((int) ev.getX(), (int) ev.getY());
        String lng = Double.toString(loc.getLongitudeE6() / 1e6);
        String lat = Double.toString(loc.getLatitudeE6() / 1e6);

        new mapStations().execute();

        Toast.makeText(getApplicationContext(),
                "Lat: " + lat + " Lng: " + lng, Toast.LENGTH_SHORT).show();
    }

    return super.dispatchTouchEvent(ev);
}

private class mapStations extends AsyncTask<Void, Void, Void> {

    @Override
    protected Void doInBackground(Void... arg0) {
        try {
            JSONObject obj = new JSONObject(API.nearByStations(lat, lng, 0));
            JSONArray stations = obj.getJSONArray("stations");
            for (int j = 0; j < stations.length(); j++) {
                JSONObject jsonObject = stations.getJSONObject(j);
                add(jsonObject.getDouble("lat"), jsonObject.getDouble("lng"));

            }

        } catch (JSONException e) {
            e.printStackTrace();
        }

        return null;
    }
}

public void add(double lat, double lng) {

    mapOverlays = mapView.getOverlays();
    drawable = this.getResources().getDrawable(R.drawable.androidmarker);
    itemizedOverlay = new MapsOverlay(drawable);

    GeoPoint point = new GeoPoint((int) (lat * 1e6), (int) (lng * 1e6));
    OverlayItem overlayitem = new OverlayItem(point, "", "");

    itemizedOverlay.addOverlay(overlayitem);
    mapOverlays.add(itemizedOverlay);
}

LogCat:

12-18 22:52:01.076: E/AndroidRuntime(25072): FATAL EXCEPTION: main
12-18 22:52:01.076: E/AndroidRuntime(25072): java.util.ConcurrentModificationException
12-18 22:52:01.076: E/AndroidRuntime(25072):    at java.util.ArrayList$ArrayListIterator.next(ArrayList.java:576)
12-18 22:52:01.076: E/AndroidRuntime(25072):    at com.google.android.maps.OverlayBundle.draw(OverlayBundle.java:41)
12-18 22:52:01.076: E/AndroidRuntime(25072):    at com.google.android.maps.MapView.onDraw(MapView.java:530)
12-18 22:52:01.076: E/AndroidRuntime(25072):    at android.view.View.draw(View.java:6880)
12-18 22:52:01.076: E/AndroidRuntime(25072):    at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
12-18 22:52:01.076: E/AndroidRuntime(25072):    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
12-18 22:52:01.076: E/AndroidRuntime(25072):    at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
12-18 22:52:01.076: E/AndroidRuntime(25072):    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
12-18 22:52:01.076: E/AndroidRuntime(25072):    at android.view.View.draw(View.java:6883)
12-18 22:52:01.076: E/AndroidRuntime(25072):    at android.widget.FrameLayout.draw(FrameLayout.java:357)
12-18 22:52:01.076: E/AndroidRuntime(25072):    at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
12-18 22:52:01.076: E/AndroidRuntime(25072):    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
12-18 22:52:01.076: E/AndroidRuntime(25072):    at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
12-18 22:52:01.076: E/AndroidRuntime(25072):    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
12-18 22:52:01.076: E/AndroidRuntime(25072):    at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
12-18 22:52:01.076: E/AndroidRuntime(25072):    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
12-18 22:52:01.076: E/AndroidRuntime(25072):    at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
12-18 22:52:01.076: E/AndroidRuntime(25072):    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
12-18 22:52:01.076: E/AndroidRuntime(25072):    at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
12-18 22:52:01.076: E/AndroidRuntime(25072):    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
12-18 22:52:01.076: E/AndroidRuntime(25072):    at android.view.View.draw(View.java:6883)
12-18 22:52:01.076: E/AndroidRuntime(25072):    at android.widget.FrameLayout.draw(FrameLayout.java:357)
12-18 22:52:01.076: E/AndroidRuntime(25072):    at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
12-18 22:52:01.076: E/AndroidRuntime(25072):    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
12-18 22:52:01.076: E/AndroidRuntime(25072):    at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
12-18 22:52:01.076: E/AndroidRuntime(25072):    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
12-18 22:52:01.076: E/AndroidRuntime(25072):    at android.view.View.draw(View.java:6883)
12-18 22:52:01.076: E/AndroidRuntime(25072):    at android.widget.FrameLayout.draw(FrameLayout.java:357)
12-18 22:52:01.076: E/AndroidRuntime(25072):    at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:2106)
12-18 22:52:01.076: E/AndroidRuntime(25072):    at android.view.ViewRoot.draw(ViewRoot.java:1562)
12-18 22:52:01.076: E/AndroidRuntime(25072):    at android.view.ViewRoot.performTraversals(ViewRoot.java:1298)
12-18 22:52:01.076: E/AndroidRuntime(25072):    at android.view.ViewRoot.handleMessage(ViewRoot.java:1911)
12-18 22:52:01.076: E/AndroidRuntime(25072):    at android.os.Handler.dispatchMessage(Handler.java:99)
12-18 22:52:01.076: E/AndroidRuntime(25072):    at android.os.Looper.loop(Looper.java:130)
12-18 22:52:01.076: E/AndroidRuntime(25072):    at android.app.ActivityThread.main(ActivityThread.java:3821)
12-18 22:52:01.076: E/AndroidRuntime(25072):    at java.lang.reflect.Method.invokeNative(Native Method)
12-18 22:52:01.076: E/AndroidRuntime(25072):    at java.lang.reflect.Method.invoke(Method.java:507)
12-18 22:52:01.076: E/AndroidRuntime(25072):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
12-18 22:52:01.076: E/AndroidRuntime(25072):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
12-18 22:52:01.076: E/AndroidRuntime(25072):    at dalvik.system.NativeStart.main(Native Method)

In a later note I would like to have different icons for each point and a tap event to bring up more details about that point the user taps. I spent about six hours on this last night and could not figure it out. The logcat doesn’t really tell much.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T14:25:22+00:00Added an answer on May 27, 2026 at 2:25 pm

    You should add the items in the UI thread, not in background.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating a map application.I want that as a person travels from his
I'm creating a java desktop application that draws a map in a JFrame designing
I am thinking of creating a web application that shows a map of a
I'm creating a Go Google App Engine application that will be making HTTP JSON
I'm creating an application with a weather map that shows the heat as a
I am currently creating an application (iPhone/iPad/Android) that uses a map to display houses
I'm creating a map using Google Fusion Tables. It has several layers that are
I have a problem creating a std::map<int, int> from a vector of pointers, called
I'm creating an asp.net page that uses the google map api. The page loads
I am working on creating a Java class to map an XML file that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.