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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T00:33:24+00:00 2026-06-03T00:33:24+00:00

Hello I am writing an app that makes the use of coordinates from a

  • 0

Hello I am writing an app that makes the use of coordinates from a webserver. I know how to retrieve the coordinates from the webservice, but once I get them how can I constantly display them on the map. Sort of like the Location Listener updates the point on the map when the location from the location manager changes. I want to constantly update the points I receive from the webservice.
Is this done with a Service? If so how?

        public class GeoUpdateHandler implements LocationListener {  

        @Override  
        public void onLocationChanged(Location location) {  
            ...
                GeoPoint point = new GeoPoint(lat, lng);  
            createMarker();  
            mapController.animateTo(point); // mapController.setCenter(point);  
        }  

UPDATED: Code for Createmarker

private void createMarker() {  
        GeoPoint p = mapView.getMapCenter();  
        OverlayItem overlayitem = new OverlayItem(p, "", "");  
        itemizedoverlay.addOverlay(overlayitem);  
        mapView.getOverlays().add(itemizedoverlay);  
    }  

UPDATED: Code for getting coordinates from webservice…

HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost(".../android/serverFile.php");
        JSONObject json = new JSONObject();
        try {
            JSONArray postjson=new JSONArray();
            postjson.put(json);
            // Execute HTTP Post Request
            System.out.print(json);
            HttpResponse response = httpclient.execute(httppost);
            // for JSON:
            if(response != null)
            {
                InputStream is = response.getEntity().getContent();
                BufferedReader reader = new BufferedReader(new InputStreamReader(is));
                StringBuilder sb = new StringBuilder();
                String line = null;
                try {
                    while ((line = reader.readLine()) != null) {
                        sb.append(line + "\n");
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                } finally {
                    try {
                        is.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
                String jsonStr = sb.toString();
                JSONObject jsonObj = new JSONObject(jsonStr);
                String longitudecord = jsonObj.getString("lon");
                String latitudecord = jsonObj.getString("lat");

}

UPDATE WITH TIMER:

public void startService(){
    timer.scheduleAtFixedRate(new TimerTask(){
        @Override
        public void run() {
                 //Call the method that contacts the server and  
                 //adds the coordinates to a list. Get those values from the list.  
            HttpClient httpclient = new DefaultHttpClient();
            HttpPost httppost = new HttpPost("http://www.kre8tiveinspired.com/android/serverFile.php");
            JSONObject json = new JSONObject();

            try {
                // JSON data:
                JSONArray postjson=new JSONArray();
                postjson.put(json);
                // Execute HTTP Post Request
                System.out.print(json);
                HttpResponse response = httpclient.execute(httppost);
                // for JSON:
                if(response != null)
                {
                    InputStream is = response.getEntity().getContent();
                    BufferedReader reader = new BufferedReader(new InputStreamReader(is));
                    StringBuilder sb = new StringBuilder();
                    String line = null;
                    try {
                        while ((line = reader.readLine()) != null) {
                            sb.append(line + "\n");
                        }
                    } catch (IOException e) {
                        e.printStackTrace();
                    } finally {
                        try {
                            is.close();
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                    }
                    String jsonStr = sb.toString();
                    JSONObject jsonObj = new JSONObject(jsonStr);
                    // grabbing the menu object 
                    String longitudecord = jsonObj.getString("lon");
                    String latitudecord = jsonObj.getString("lat");
                    latcord = latitudecord;
                    loncord = longitudecord;
                }

            }catch (ClientProtocolException e) {
                // TODO Auto-generated catch block
            } catch (IOException e) {
                // TODO Auto-generated catch block
            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
                 Handler handler = new Handler();
                 handler.post(new Runnable(){  
                       public void run(){

                        double aDouble = Double.parseDouble(loncord);
                    double bDouble = Double.parseDouble(latcord);

                    int lat = (int) (aDouble * 1E6);  
                        int lng = (int) (bDouble * 1E6);  
                        GeoPoint point = new GeoPoint(lat, lng);  
                        createMarker();  
                        mapController.animateTo(point); // mapController.setCenter(point);
                            //add the overlays to the map
                            // and call invalidate for the mapview.
                             mapView.invalidate();

                       }
                 });
            }

    }, 0, 1000); // Here im calling the timer every 10 seconds
  • 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-03T00:33:26+00:00Added an answer on June 3, 2026 at 12:33 am

    Well what you can do is to use a timer to populate the map. Basically, you can have one method which contacts the server, fetches the coordinates and adds them into an arraylist. Now this method can be called from inside the timer (which can run every few seconds, depending on your needs). Also, inside this timer class, you can re-populate the map. Some code for this:

    timer=new Timer();  // Refresh map via timer task.
        timer.scheduleAtFixedRate(new TimerTask(){
            @Override
            public void run() {
                     //Call the method that contacts the server and  
                     //adds the coordinates to a list. Get those values from the list.  
                     Handler handler = new Handler();
                     handler.post(new Runnable(){  
                           public void run(){
                                //add the overlays to the map
                                // and call invalidate for the mapview.
                           }
                     });
                }
    
        }, 0, 10000); // Here im calling the timer every 10 seconds
    

    If you would want to look at an example project that uses this idea, head here, and have a look at the timer inside onResume(). It uses another class called FetchParse that contacts the server and gets the updated list of coordinates.

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

Sidebar

Related Questions

Hello I'm writing a little Android app (Version 2.3.3). Now i get this strange
Hello Im currently writing a product syncronisation script for magento. I know how to
Hello I am writing some data structures in C, and I've realized that their
I am re-writing (yeah I know!) a Rails app which is largely API driven,
Hello I'm writing an application that uses the compatibility library and i'm using a
I have got Eclipse to generate a Basic android Hello World app, But it
I thought I had this all figured out, but now that I'm writing a
I'm writing a web app that is sending some straight files in response to
I am writing a Mac app that uses Core Data as its persistence layer,
Writing an app which takes a picture from the camera and retrieves it as

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.