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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:35:36+00:00 2026-06-11T21:35:36+00:00

i have this gps method: if (globalconstant.gps) { globalconstant.mlocManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); globalconstant.mlocManager .addGpsStatusListener(main.this);

  • 0

i have this gps method:

if (globalconstant.gps) {
                            globalconstant.mlocManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
                            globalconstant.mlocManager
                                    .addGpsStatusListener(main.this);
                            Log.w("TravellerLog :: ", "22");
                            addGPSListener();
                            ProgressDialog MyDialog = ProgressDialog.show(
                                    main.this, "Info",
                                    " GPS kapcsolódásra vár... ", true);}

…

/* GPS kapcsolódás figyelő */
    public void onGpsStatusChanged(int event) {

        // Log.w("TravellerLog :: ", "l1");
        switch (event) {
        case GpsStatus.GPS_EVENT_SATELLITE_STATUS:
            break;
        case GpsStatus.GPS_EVENT_FIRST_FIX:

            show_sens = show_sens + "- GPS\n";
            sensors.setText(show_sens);
            Toast.makeText(getApplicationContext(), "GPS kapcsolódva!",
                    Toast.LENGTH_SHORT).show();
                                                // Co-ordinates
            myChronometer.stop();
            myChronometer.setBase(SystemClock.elapsedRealtime());
            meres = false;
            start_button.setText("START");
            break;
        case GpsStatus.GPS_EVENT_STARTED:
            break;
        case GpsStatus.GPS_EVENT_STOPPED:
            break;
        }
    }

the addGPSListener()

// GPS
    private void addGPSListener() {

        globalconstant.db.setVersion(1);
        globalconstant.db.setLocale(Locale.getDefault());
        globalconstant.db.setLockingEnabled(true);

        final String gps =

        "CREATE TABLE IF NOT EXISTS GPS_Values ("

                + "id INTEGER PRIMARY KEY AUTOINCREMENT, Latitude float(10, 8), Longitude float(10, 8),Accuracy INTEGER,Speed INTEGER,City TEXT,timestamp TIMESTAMP);";
        globalconstant.db.execSQL(gps);

        Log.d("FESTIVALE :: ", "Frissítési idő: "
                + globalconstant.gps_update_value);
        float f = Float.valueOf(globalconstant.gps_update_value.trim())
                .floatValue();
        float update = f * 1000;

        globalconstant.mlocManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        globalconstant.mlocListener = new MyLocationListener();
        globalconstant.mlocManager.requestLocationUpdates(
                LocationManager.GPS_PROVIDER, (long) update, 5f,
                globalconstant.mlocListener);

        // if(Global.getInstance().currentGPSLocation != null){
        //
        // }

    }

    public class MyLocationListener implements LocationListener {

        public void onLocationChanged(Location loc) {

            float szel = (float) loc.getLatitude();
            float hossz = (float) loc.getLongitude();
            int horiAcc = (int) (loc.getAccuracy());
            // int speed=(int) ((loc.getSpeed()*3600)/1000); //sebesség km/h-ban
            int speed = 0;

            if (loc.hasSpeed()) {
                speed = (int) ((loc.getSpeed() * 3600) / 1000); // sebesség
                                                                // km/h-ban
            } else {
                speed = 0;
            }

            String test = String.format("%.08f", szel);
            String test2 = String.format("%.08f", hossz);

            Geocoder geocoder = new Geocoder(main.this, Locale.getDefault());
            try {
                List<Address> addresses = geocoder.getFromLocation(szel, hossz,
                        1);
                city = addresses.get(0).getLocality();
            } catch (IOException e) {
                e.printStackTrace();
            }

            ContentValues gps_values = new ContentValues();

            gps_values.put("Latitude", test);
            gps_values.put("Longitude", test2);
            gps_values.put("Accuracy", horiAcc);
            gps_values.put("Speed", speed);
            gps_values.put("City", city);

            SimpleDateFormat dateFormat = new SimpleDateFormat(
                    "yyyy-MM-dd HH:mm:ss");
            Date date = new Date(System.currentTimeMillis());

            gps_values.put("timestamp", dateFormat.format(date));

            try {
                globalconstant.db.beginTransaction();
                globalconstant.db.insert("GPS_Values", null, gps_values);
                globalconstant.db.setTransactionSuccessful();
            } finally {
                globalconstant.db.endTransaction();
            }

            Log.d("FESTIVALE :: ",
                    "Hely " + test + ", " + test2 + " , " + horiAcc + " , "
                            + speed + " , " + city + ","
                            + dateFormat.format(date));
            // String Text = "My current location is: " + "Latitude = "
            // + loc.getLatitude() + "\nLongitude = " + loc.getLongitude();

            // Toast.makeText(getApplicationContext(), "Hely" +test + "\n" +
            // test2 + "\n" + horiAcc + "\n" +speed + "\n" +city,
            // Toast.LENGTH_SHORT)
            // .show();

        }

        public void onProviderDisabled(String provider) {

        }

        public void onProviderEnabled(String provider) {
            //
        }

        public void onStatusChanged(String provider, int status, Bundle extras) {
            /* This is called when the GPS status alters */
            switch (status) {
            case LocationProvider.OUT_OF_SERVICE:
                Log.v(tag, "Status Changed: Out of Service");
                Toast.makeText(main.this, "Status Changed: Out of Service",
                        Toast.LENGTH_SHORT).show();
                break;
            case LocationProvider.TEMPORARILY_UNAVAILABLE:
                Log.v(tag, "Status Changed: Temporarily Unavailable");
                Toast.makeText(main.this,
                        "Status Changed: Temporarily Unavailable",
                        Toast.LENGTH_SHORT).show();
                break;
            case LocationProvider.AVAILABLE:
                Log.v(tag, "Status Changed: Available");
                Toast.makeText(main.this, "Status Changed: Available",
                        Toast.LENGTH_SHORT).show();
                break;
            }

        }

    }// gps vége

so the question is how can i manage that the gps listener (store in the database the coordinnates…) olny starts when the gps fixed?
thanks for your answers!

  • 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-11T21:35:37+00:00Added an answer on June 11, 2026 at 9:35 pm

    You have coded properly, only you need to check certain condition, if the condition gets fulfill then just add lat-lon details to sql, do as follows,

    case GpsStatus.GPS_EVENT_FIRST_FIX:
    {
    
        ...
        ...
        ...
    
        new DBThread().start();
    }
    break;
    
    private class DBThread extends Thread
    { 
         public void run()
         {
            // Fetch Lat-lon details here and store in sqlite
    
            ...
            // Remove gps code to save in battery from drain soon
         }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a service that runs this thread to get GPS coordinates LocationManager lm
I have this form: <%= form_tag posts_path, :method => :get, :class => search_nav do
I have a few questions about CoreLocation and GPS. First, what method in core
I am using the requestLocationUpdates method of LocationManager to get GPS location updates. I
I have this error . even I have set the persmmissinos for GPS >>
Does LocationManager have the ability to change, from example, from GPS to a more
In this app I am trying to have a user enter GPS coordinates and
I'm trying to have GPS coordinates sent to a text message. This code works,
my problem is this one, I have a javascript code that gets GPS location
I have the following code: if (gps_enabled) { Log.e($$$$$$$$$$$$$$, GPS is enabled requestion location

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.