import java.io.IOException; import java.util.List; import java.util.Locale; import com.google.android.maps.GeoPoint; import android.content.Context; import android.location.Address; import android.location.Geocoder; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; import android.os.Bundle; import android.os.Message; import android.util.Log; public class GeoDataGateway implements LocationListener{ //message for update handler private static final int UPDATE_LOCATION = 0; private static final int GPS_OFF = 1; private static final int GPS_ON = 2; //system vars public LocationManager lm = null; private MainActivity SystemService = null; //lat, lng private double mLongitude = 0; private double mLatitude = 0; public String city = ""; public String street = ""; public GeoDataGateway(MainActivity sservice){ this.SystemService = sservice; this.startLocationService(); } public void startLocationService(){ this.lm = (LocationManager) this.SystemService.getSystemService(Context.LOCATION_SERVICE); this.lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 3000, 2, this); } public double getLongitude(){ return this.mLongitude; } public double getLatitude(){ return this.mLatitude; } public GeoPoint getCurrentPoint(){ if((this.mLongitude != 0) & (this.mLatitude != 0)){ return new GeoPoint((int)(this.mLatitude*1E6), (int)(this.mLongitude*1E6)); }else{ return new GeoPoint(0,0); } } public void onLocationChanged(Location location) { location = this.lm.getLastKnownLocation(LocationManager.GPS_PROVIDER); try { this.mLongitude = location.getLongitude(); this.mLatitude = location.getLatitude(); Message msg = Message.obtain(); msg.what = UPDATE_LOCATION; this.SystemService.myViewUpdateHandler.sendMessage(msg); } catch (NullPointerException e) { Log.i("Null pointer exception " + mLongitude + "," + mLatitude, null); } } public void onProviderDisabled(String provider) { } public void onProviderEnabled(String provider) { } public void onStatusChanged(String provider, int status, Bundle extras) { } }