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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:23:28+00:00 2026-05-25T03:23:28+00:00

my app records the gps location on a button click; however when I do

  • 0

my app records the gps location on a button click; however when I do it says I’m about three blocks away and is extremely inaccurate. Can you take a look at my code to see how I can improve it? Thanks

@Override
        protected Void doInBackground(Void... arg0) {
            SharedPreferences prefs = getSharedPreferences("Settings", 0);
            final String id = prefs.getString("ID", "");
            DefaultHttpClient httpclient = new DefaultHttpClient();
            HttpPost httpost = new HttpPost(
                    "http://iphone-radar.com/gps/gps_locations");

            JSONObject holder = new JSONObject();

            try {
                holder.put("id", id);
                LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
                Criteria criteria = new Criteria();
                String bestProvider = locationManager.getBestProvider(criteria,
                        false);
                LocationListener loc_listener=new LocationListener() {

                    @Override
                    public void onStatusChanged(String provider, int status, Bundle extras) {
                        // TODO Auto-generated method stub

                    }

                    @Override
                    public void onProviderEnabled(String provider) {
                        // TODO Auto-generated method stub

                    }

                    @Override
                    public void onProviderDisabled(String provider) {
                        // TODO Auto-generated method stub

                    }

                    @Override
                    public void onLocationChanged(Location location) {
                        // TODO Auto-generated method stub

                    }
                };
                try{
                    Looper.prepare();
                locationManager.requestLocationUpdates(bestProvider, 0, 0, loc_listener);
                }catch(Exception e){
                    e.printStackTrace();
                }
                Location location=locationManager.

getLastKnownLocation(bestProvider);
            Calendar c = Calendar.getInstance();
            SimpleDateFormat sdf = new SimpleDateFormat("hh:mmaa dd'/'MM'/'yyyy");

            holder.put("time", sdf.format(c.getTime()));
            holder.put("time_since_epoch", System.currentTimeMillis());
            try {
                holder.put("lat", location.getLatitude());
                holder.put("lon", location.getLongitude());
            } catch (NullPointerException e) {
                try {
                    holder.put("lat", -1.0);
                    holder.put("lon", -1.0);
                } catch (JSONException e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                }
            }

            StringEntity se = new StringEntity(holder.toString());
            httpost.setEntity(se);
            httpost.setHeader("Accept", "application/json");
            httpost.setHeader("Content-type", "application/json");

            ResponseHandler responseHandler = new BasicResponseHandler();
            String response = httpclient.execute(httpost, responseHandler);
            org.json.JSONObject obj;

                obj = new org.json.JSONObject(response);

        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (UnsupportedEncodingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (ClientProtocolException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
  • 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-25T03:23:29+00:00Added an answer on May 25, 2026 at 3:23 am

    Yes there absolutely is, try adding some accuracy to your Criteria…

    Criteria criteria = new Criteria();
    criteria.setAccuracy(Criteria.ACCURACY_FINE);
    

    The default constructor for Criteria states (emphasis mine)

    Constructs a new Criteria object. The new object will have no requirements on accuracy, power, or response time; will not require altitude, speed, or bearing; and will not allow monetary cost.

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

Sidebar

Related Questions

I can't seem to delete old records from my app on heroku. Currently the
In my app I have venue records where each one can have many photos
My PHP app has an import script that can import records. At the moment,
I'm making a GPS app that will deals with 200 millions records in a
I have an app in which records audio files. User can specify length of
I'm converting an old app that records folder sizes on a daily basis. The
I'm trying to query records in Google App engine where an IntegerProperty is null
In our current WinForms app, we are displaying millions of records in ListView, using
I'm working on a MVC based web app on LAMP that needs some records
I'm working on a WinForms app and need to record the location of MouseDown

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.