Store GPS changes in an array then email them out

Put problem concerning MapActivities, MapViews, Overlays and GPS in this forum.

Store GPS changes in an array then email them out

Postby rd42 » Thu Apr 01, 2010 6:15 pm

I'm trying to store GPS changes in an array then email them out after a select amount of time. I'm new to java so I'm not sure if I should use an array to keep the returns of location.toString() or a collection.

I now the data is showing up because I see it when I run adb logcat from the tools directory. I'm just not sure how to collect it up and ship it out. I was guessing I would do collect the info in the method, onLocationChanged and the send it to another method to be emailed out or stored in a file or db or some earwax.

Thanks for any ideas or pointers.


Here is my code:

Code: Select all
package edu.xxx.xxx.xxxx;

import android.app.Activity;
import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;

public class xxxxxxxx extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
       
       //<=================================================
       //   Calling parent and pass in savedInstanceState
       //<=================================================
       super.onCreate(savedInstanceState);
       
        //<=================================================
       //   Calling parent setContentView
       //<=================================================
       
        setContentView(tv);
          setupListener();
   
    private void setupListener()
    {
       //<=========================================================================
       //   get locationMananger object from the system service map
       //<=========================================================================
       LocationManager locm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
       
       
          //Location loc = locm.getLastKnownLocation("gps");
          Log.d("LSKFLKEasdfawefawefew", "EHHLOOO");
          
          //<==========================================================================
          //  Instantiate and override methods in the LocationListener
          //   Could be done with subclassing
          //<==========================================================================
          LocationListener onLocationChange=new LocationListener() {
              public void onLocationChanged(Location location) {
                 //updateForecast(location);
                 //Log.d("TSETTESTE" , "Updataed position " + location.toString());
                 System.out.println(">>>>>>>>>>>>>>>>--- Collecting GPS Data ---<<<<<<<<<<<<<<<<");             
                 
                //System.out.println(location.toString());
                 
                 
              } public void onProviderDisabled(String provider) {
                 // required for interface, not used
              }
              public void onProviderEnabled(String provider) {
                 // required for interface, not used
              }

              public void onStatusChanged(String provider, int status, Bundle extras) {
                 // required for interface, not used
              }};

              //<==================================================================
              //   register the listener with the Location Manager to receive
              //   updates when the nav data changes
              //<==================================================================

          locm.requestLocationUpdates("gps", 5, 1, onLocationChange);
       
    }

}
User avatar
rd42
Junior Developer
Junior Developer
 
Posts: 22
Joined: Thu Apr 01, 2010 5:12 pm

Top

Postby nicholas.hauschild » Mon Apr 05, 2010 5:46 am

Hello rd42,

You could use a member variable of type String[] to save your location strings, but since it appears that you wont know how many locations you will be adding, perhaps you would like to use a List<String>, which will dynamically adjust size when necessary.

Each time onLocationChanged() receives a callback, you can add the location to your List<String> via the .add(String) method.

If you need anymore help, let me know. And good luck!
nicholas.hauschild
Master Developer
Master Developer
 
Posts: 310
Joined: Fri Dec 04, 2009 4:50 am

Postby rd42 » Mon Apr 05, 2010 1:46 pm

nicholas.hauschild thanks!

I'll try that. Just playing I had it sent SMS to my iPhone onLocationChanged and it was using the network instead of gps to get location which changes location even when you are sitting still. It was funny, it started blasting my iPhone with messages, rapid fire.

Thanks for the info.
User avatar
rd42
Junior Developer
Junior Developer
 
Posts: 22
Joined: Thu Apr 01, 2010 5:12 pm

Postby nicholas.hauschild » Mon Apr 05, 2010 11:13 pm

This is off the top of my head, but I do believe that you can specify an amount of time between updates.

If it were me receiving those SMS, I could image that would cost me a lot of money :)
nicholas.hauschild
Master Developer
Master Developer
 
Posts: 310
Joined: Fri Dec 04, 2009 4:50 am

Postby rd42 » Tue Apr 06, 2010 12:10 am

So true, when it happened I wasn't sure what the work phone had in it's plan. I thought it was funny though. You can specify the update cycle, maybe I should do that. :)
User avatar
rd42
Junior Developer
Junior Developer
 
Posts: 22
Joined: Thu Apr 01, 2010 5:12 pm

Top

Return to Map Problems

Who is online

Users browsing this forum: No registered users and 6 guests