0

I need a simple android app which can be installed on any android supporting device; I need this app to send the coordinates of its current location every 5 minutes so that it can be sent to sql database

Thanks

This is the code from which i am showing my current location and getting the co-ordinates values(as toast message for now) Now i need to send this location co-ordinate to the database after every 5 minutes

import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.MyLocationOverlay;
import com.iconnectgroup.LocateDeviceApp.Gps.MyPositionOverlay;

import android.content.Context;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;

public class HelloGoogleMaps extends MapActivity {

MapController mapController;
MyLocationOverlay myLocationOverlay ;
MyPositionOverlay positionOverlay;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    final MapView mapView = (MapView) findViewById(R.id.mapview);
    mapView.setBuiltInZoomControls(true);     
    mapController = mapView.getController();
    mapController.setZoom(17);
    Criteria criteria = new Criteria();
    criteria.setAccuracy(Criteria.ACCURACY_FINE);
    criteria.setAltitudeRequired(false);
    criteria.setBearingRequired(false);
    criteria.setCostAllowed(true);
    criteria.setPowerRequirement(Criteria.POWER_LOW);
    mapView.setStreetView(true);

myLocationOverlay = new MyLocationOverlay(this, mapView);
mapView.getOverlays().add(myLocationOverlay);

myLocationOverlay.runOnFirstFix(new Runnable() {
public void run() {
    mapView.getController().animateTo(
      myLocationOverlay.getMyLocation());

    }
});

LocationManager mlocManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);

LocationListener mlocListener = new MyLocationListener();
mlocManager.requestLocationUpdates( LocationManager.GPS_PROVIDER, 0, 0, mlocListener);

}

public class MyLocationListener implements LocationListener
{

  @Override
  public void onLocationChanged(Location loc)
  {

    loc.getLatitude();
    loc.getLongitude();

    String Text = "Truck location is: " +
    "Latitude = " + loc.getLatitude() +
    "Longitude = " + loc.getLongitude();

    Toast.makeText( getApplicationContext(), Text, Toast.LENGTH_LONG).show();
    Log.e("co-ordinates are:", Text);
  }

  @Override
  public void onProviderDisabled(String provider)
  {
    Toast.makeText( getApplicationContext(), "Gps Disabled", Toast.LENGTH_LONG ).show();
  }

  @Override
  public void onProviderEnabled(String provider)
  {
    Toast.makeText( getApplicationContext(), "Gps Enabled", Toast.LENGTH_LONG).show();
  }

  @Override
  public void onStatusChanged(String provider, int status, Bundle extras)
  {

  }
 }


@Override
protected void onResume() {

super.onResume();
myLocationOverlay.enableCompass(); 
myLocationOverlay.enableMyLocation(); 
}

@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
myLocationOverlay.disableCompass(); 
myLocationOverlay.disableMyLocation(); 
}
@Override
protected boolean isRouteDisplayed() {
    // TODO Auto-generated method stub
    return false;
}
}
mak
  • 57
  • 4
  • 11
  • What's your question? What did you try? – Harald Wilhelm Jun 01 '12 at 05:07
  • i have created one map view..now i need to show current location on the map view and send this coordinate to database after every five minutes – mak Jun 01 '12 at 05:15
  • 1
    Is the mapview necessary to your app? You can get and send location data every 5 minutes without it. Check out this answer http://stackoverflow.com/questions/3145089/what-is-the-simplest-and-most-robust-way-to-get-the-users-current-location-in-a/3145655#3145655 – Phobos Jun 01 '12 at 05:44
  • check this example to [Get Current location](http://rdcworld-android.blogspot.in/2012/01/get-current-location-coordinates-city.html) or have look on this tutorial for [Get location updates after time interval](http://rdcworld-android.blogspot.in/2012/05/calculate-device-moving-speed.html) (like 5 seconds) – swiftBoy Jun 01 '12 at 08:53

0 Answers0