Created
July 17, 2012 19:10
-
-
Save Ginny/3131343 to your computer and use it in GitHub Desktop.
GPSMarker
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package cz.gnipjan.gpsmarker; | |
| import java.io.BufferedWriter; | |
| import java.io.File; | |
| import java.io.FileWriter; | |
| import java.io.IOException; | |
| import android.location.Criteria; | |
| import android.location.Location; | |
| import android.location.LocationListener; | |
| import android.location.LocationManager; | |
| import android.net.Uri; | |
| import android.os.Bundle; | |
| import android.app.Activity; | |
| import android.content.Context; | |
| import android.content.Intent; | |
| import android.content.SharedPreferences; | |
| import android.util.Log; | |
| import android.view.Menu; | |
| import android.view.MenuItem; | |
| import android.view.View; | |
| import android.widget.Button; | |
| import android.widget.Toast; | |
| import android.support.v4.app.NavUtils; | |
| public class MainActivity extends Activity { | |
| static Context context; | |
| private LocationManager locationManager; | |
| MyLocationListener locationListener; | |
| public static String lastLatitude; | |
| public static String lastLongitude; | |
| @Override | |
| public void onCreate(Bundle savedInstanceState) { | |
| super.onCreate(savedInstanceState); | |
| setContentView(R.layout.activity_main); | |
| MainActivity.context = getApplicationContext(); | |
| getLocation(); | |
| } | |
| public void getLocation() | |
| { | |
| locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); | |
| locationListener = new MyLocationListener(); | |
| locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 2000, 10, locationListener); | |
| } | |
| @Override | |
| protected void onPause() { | |
| super.onPause(); | |
| locationManager.removeUpdates(locationListener); | |
| } | |
| @Override | |
| protected void onStop() { | |
| super.onStop(); | |
| locationManager.removeUpdates(locationListener); | |
| } | |
| @Override | |
| protected void onDestroy() { | |
| super.onDestroy(); | |
| locationManager.removeUpdates(locationListener); | |
| } | |
| @Override | |
| protected void onResume() { | |
| // TODO Auto-generated method stub | |
| super.onResume(); | |
| getLocation(); | |
| } | |
| } | |
| class MyLocationListener implements LocationListener | |
| { | |
| String latitude; | |
| String longitude; | |
| String coordinatesOutput; | |
| String coordinatesWrite; | |
| public void onLocationChanged(Location loc) | |
| { | |
| if (loc != null) { | |
| double lat = loc.getLatitude(); | |
| double lon = loc.getLongitude(); | |
| latitude = Double.toString(lat); | |
| longitude = Double.toString(lon); | |
| MainActivity.lastLatitude = latitude; | |
| MainActivity.lastLongitude = longitude; | |
| } | |
| } | |
| @Override | |
| public void onProviderDisabled(String provider) { | |
| // TODO Auto-generated method stub | |
| } | |
| @Override | |
| public void onProviderEnabled(String provider) { | |
| // TODO Auto-generated method stub | |
| } | |
| @Override | |
| public void onStatusChanged(String provider, int status, Bundle extras) { | |
| // TODO Auto-generated method stub | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment