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

The Archive Base Latest Questions

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

I’m working on organizing my application and I need some help sending the GPS

  • 0

I’m working on organizing my application and I need some help sending the GPS coordiates to another class that sends them to a database. When the send button in the Main activity is pressed, it starts an intent that begins the LocationActivity. From there, I’d like to send the GPS coordinates to the SendActivity which sends them to a database (through a PHP program). How do I send the coordinates to SendActivity? I comment a section where I tried but it doesn’t work. Any help would be appreciated. Thanks!

LocationActivity.java:

public class LocationActivity extends Activity{

    private LocationManager locManager;
    private LocationListener locListener;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        startLocation();
    }

    private void startLocation()
    {   
        //get a reference to the LocationManager
        locManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);

        //checked to receive updates from the position
        locListener = new LocationListener() {
            public void onLocationChanged(Location location) {
                SendActivity.send(location); //What to do here?
            }
            public void onProviderDisabled(String provider){
                //labelState.setText("Provider OFF");
            }
            public void onProviderEnabled(String provider){
                //labelState.setText("Provider ON ");
            }
            public void onStatusChanged(String provider, int status, Bundle extras){
                //Log.i("", "Provider Status: " + status);
            }
        };

        locManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locListener);
    }
}

SendActivity.java:

public class SendActivity extends Activity {


    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    void send(Location loc)
    {
        Log.i("", String.valueOf(loc.getLatitude() + " - " + String.valueOf(loc.getLongitude())));
         String lat = String.valueOf(loc.getLatitude()); 
         String lon = String.valueOf(loc.getLongitude());

        SharedPreferences shared = getSharedPreferences("PEOPLE_PREFERENCES", MODE_PRIVATE);
        final String usr_id2 = shared.getString("USR_ID", "none");

        if (lat != "0" && lon != "0")   
        {
            HttpClient httpclient = new DefaultHttpClient();
            HttpPost httppost = new HttpPost("http://example.com/test/example.php");
         try {
           List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
           nameValuePairs.add(new BasicNameValuePair("lat", lat)); 
           nameValuePairs.add(new BasicNameValuePair("lon", lon));
           nameValuePairs.add(new BasicNameValuePair("id", usr_id2));
           httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
           httpclient.execute(httppost);
         } 
         catch (ClientProtocolException e) {
             // TODO Auto-generated catch block
         } 
         catch (IOException e) {
             // TODO Auto-generated catch block
         }

        }
    }
}
  • 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-30T14:21:11+00:00Added an answer on May 30, 2026 at 2:21 pm

    No need to create an Activity to get LatLong..
    Following is the class to get LatLong :

    class UpdateGeoLocation {
        LocationManager locationManager;
        String provider;
        double lat, lng;
        Location location;
        Location returnlocation;
        Context context;
    
        public static String locationdetails = null;
    
        public UpdateGeoLocation(Context context) {
            this.context = context;     
            Criteria criteria = new Criteria();
            criteria.setAccuracy(Criteria.ACCURACY_FINE);
            locationManager = (LocationManager) context
                    .getSystemService(Context.LOCATION_SERVICE);
            provider = locationManager.getBestProvider(criteria, true);
            location = locationManager.getLastKnownLocation(provider);
            returnlocation = locationManager.getLastKnownLocation(provider);
        }
    
        public Location getLocation(Location location) {
    
            if (location != null) {
                Log.d("one", "IF getLocation :: " + location);
                returnlocation.setLatitude(location.getLatitude());
                returnlocation.setLongitude(location.getLongitude());
    
            } else {
                try {
                    listenForLocation(provider);
                } catch (NullPointerException nullPointerException) {
                    nullPointerException.printStackTrace();
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
    
            return returnlocation;
    
        }
    
        private void listenForLocation(String providerName) {
            locationManager.requestLocationUpdates(providerName, 0, 0,
                    locationListener);
            if (location != null) {
                location.getLatitude();
                location.getLongitude();
                getLocation(location);
            } else {
                // Toast.makeText(context, "location null",
                // Toast.LENGTH_SHORT).show();
            }
        }
    
        private final LocationListener locationListener = new LocationListener() {
            public void onLocationChanged(Location location) {
                returnlocation.setLatitude(location.getLatitude());
                returnlocation.setLongitude(location.getLongitude());
            }
    
            public void onProviderDisabled(String provider) {
    
            }
    
            public void onProviderEnabled(String provider) {
            }
    
            public void onStatusChanged(String provider, int status, Bundle extras) {
            }
        };
    
    }
    
    
    Following is the Activity where I used above class to get LatLong :
    
    Location location = null;
    
    OnCreate() :
    
    try {
        Looper.prepare();
        if (null != (location = requestForLocation())) {
            if (null != location) {
                Log.d("one", "Location :: " + location.getLatitude());
                Log.d("one", "Location  LATLONG :: " + location.getLongitude());
    
                            //Use intent or bundle here to send LatLong to other activities..
    
    
            } else {
                Log.d("one", "Location not found:: ");
    
            }
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    } 
    
    
    private Location requestForLocation() {
        return new UpdateGeoLocation(MonsterLoginActivity.this)
        .getLocation(null);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace

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.