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 8092637
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T20:19:40+00:00 2026-06-05T20:19:40+00:00

I am new to android programming and i am trying to develop this app

  • 0

I am new to android programming and i am trying to develop this app to call the google maps services on an android phone, then access a web service to retrieve the value of latitude and longitude of stations that need to be plotted on the map.

Foll is the code, but when i run the app the program is non responsive, it plots only one annottation and tht too the panning and zooming event is really slow and sometimes the code gets stuck.

Please help with the solution.

OpenMap.java


public class OpenMap extends MapActivity 
{

private MapController mapController;
private MyLocationOverlay myLocation;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    // Get Mapping Controllers etc
    MapView mapView = (MapView) findViewById(R.id.map_view);
    mapController = mapView.getController();
    mapController.setZoom(1);
    mapView.setBuiltInZoomControls(true);

    // Add the MyLocationOverlay
    myLocation = new MyLocationOverlay(this, mapView);
    mapView.getOverlays().add(myLocation);

    myLocation.enableMyLocation();

    DemoOverlay demoOverlay = new DemoOverlay();
    mapView.getOverlays().add(demoOverlay);
    myLocation.runOnFirstFix(new Runnable() {
        public void run() {
            mapController.animateTo(myLocation.getMyLocation());
        }
    });
}

@Override
protected void onResume() {
    super.onResume();
    myLocation.enableMyLocation();
}

@Override 
protected void onPause() {
    super.onPause();
    myLocation.disableMyLocation();
}

@Override
protected boolean isRouteDisplayed() {
    // TODO Auto-generated method stub
    return false;
}

}

DemoOverlay.java

public class DemoOverlay extends Overlay
{
ArrayList<String> arrlat_long = new ArrayList<String>();
public static String str;
public static String str1;
String responseBody;
int n=0;
 String Url =   "http://hiscentral.cuahsi.org/webservices/hiscentral.asmx/GetSeriesCatalogForBox2";
 List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(5); 
 HttpClient httpclient = new DefaultHttpClient();   
   @Override
    public void draw(Canvas canvas, MapView mapView, boolean shadow)
   {
        super.draw(canvas, mapView, shadow);
        Projection projection = mapView.getProjection();
         if(!Url.endsWith("?"))
         {
                Url += "?";
         }

            int latSpan = mapView.getLatitudeSpan();
            int lngSpan = mapView.getLongitudeSpan();
            GeoPoint mapCenter = mapView.getMapCenter();
            int mapLeftGeo = mapCenter.getLongitudeE6() - (lngSpan / 2);
            int mapRightGeo = mapCenter.getLongitudeE6() + (lngSpan / 2);

            int mapTopGeo = mapCenter.getLatitudeE6() - (latSpan / 2);
            int mapBottomGeo = mapCenter.getLatitudeE6() + (latSpan / 2);

            GeoPoint geoPoint = this.getSampleLocation();


         nameValuePairs.add(new BasicNameValuePair("xmin", "-100"));
         nameValuePairs.add(new BasicNameValuePair("xmax", "-90"));
         nameValuePairs.add(new BasicNameValuePair("ymin", "40"));
         nameValuePairs.add(new BasicNameValuePair("ymax", "55"));
         nameValuePairs.add(new BasicNameValuePair("networkIDs", ""));
         nameValuePairs.add(new BasicNameValuePair("conceptKeyword", "precipitation"));
         nameValuePairs.add(new BasicNameValuePair("beginDate", "1/1/2009"));
         nameValuePairs.add(new BasicNameValuePair("endDate", "1/1/2010"));
         String paramString = URLEncodedUtils.format(nameValuePairs, "utf-8");
         Url += paramString;

  if ((geoPoint.getLatitudeE6() > mapTopGeo && geoPoint.getLatitudeE6() < mapBottomGeo)
                 && (geoPoint.getLongitudeE6() > mapLeftGeo && geoPoint.getLongitudeE6() < mapRightGeo)) 
              {
                    geoPoint = arrlat_long(n);
                    Point myPoint = new Point();
                    projection.toPixels(geoPoint, myPoint);

                    Bitmap marker = BitmapFactory.decodeResource(mapView.getContext().getResources(), R.drawable.markerblue);

                    canvas.drawBitmap(marker, myPoint.x - 15, myPoint.y - 30, null);
                }

   }

private GeoPoint getSampleLocation() 
    {
       GeoPoint sampleGeoPoint;
      // int n=0;

       try {
              HttpPost httppost = new HttpPost(Url); 
              httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
              HttpResponse response = httpclient.execute(httppost);
              responseBody = EntityUtils.toString(response.getEntity());

            XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
            factory.setValidating(false);
            XmlPullParser myxml = factory.newPullParser();
            InputStream raw = new ByteArrayInputStream(responseBody.getBytes());
            myxml.setInput(raw, null);

            int eventType = myxml.getEventType();
            while(eventType != XmlPullParser.END_DOCUMENT) 
            {
                if(eventType == XmlPullParser.START_DOCUMENT) 
                {

                    Log.d("ParseXmlActivity", "In start document");
                }
                else if(eventType == XmlPullParser.START_TAG) 
                {
                    if (myxml.getName().equals("latitude"))
                    {
                        str="";
                        str  += "Lat:" + myxml.nextText().toString();
                         Log.d("ParseXmlActivity", "In start tag = "+str);
                         arrlat_long.add(str);
                    }
                    if (myxml.getName().equals("longitude"))
                    {
                        str1 += "--Lon:" + myxml.nextText().toString();
                         Log.d("ParseXmlActivity", "In start tag = "+str1);
                         arrlat_long.add(str1);
                    }
                } 
                eventType = myxml.next();

            }
        } 
        catch (XmlPullParserException e) 
        {
        } 
        catch (IOException e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }


   int in =Integer.parseInt(str);
       int in1 =Integer.parseInt(str1);   
       sampleGeoPoint = new GeoPoint(in,in1);
        return sampleGeoPoint;
    }}
  • 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-06-05T20:19:41+00:00Added an answer on June 5, 2026 at 8:19 pm

    I think your approach is the wrong way to do it. I cannot rewrite you the whole code, but will give you some hints, how to do it. By the way, it has absolutly nothing to do, with google apis, its you, who is speaking to webservices inside the onDraw method of the Foreground Thread (aka UI-Thread)!

    So to get off that, I would suggest the following:
    Absolutely avoid to do heavy computing inside onDraw(Canvas). Use an AsyncTask , to gather your data. After your request, you could update your MapView by calling postInvalidate() and take that to draw.

    Maybe the LazyLoad-feature of overlaymanager lib is interesting for you

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

Sidebar

Related Questions

i am new to android programming and i am trying to develop an app
I'm new in Android Programming. I'm trying to write an app that uses USB
I am new to android programming and trying to build a map activity app.
Since i am new in Phone app programming, this might be a silly question...
I'm new to Android programming and trying to wrap my head around this just
I'm trying to make an android app (I'm new in the Android programming world),
I'm still new to programming/Java/Android so I'm trying to understand everything I do and
I'm fairly new to Android programming, so this may be a simple question, but
I'm very new to Android programming, so this is probably something pretty basic. I
Hi I'm new to android programming, I'm trying to initiate the on click method

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.