package org.imogene.map.provider.osm.app;
import org.imogene.map.provider.common.Constants.Extras;
import org.imogene.map.provider.osm.overlay.BubbleClickableOverlay;
import org.osmdroid.util.GeoPoint;
import android.content.Context;
import android.content.Intent;
import android.location.Location;
import android.location.LocationManager;
import android.os.Bundle;
public class LocationPicker extends MapActivity {
private BubbleClickableOverlay mOverlay;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Location l = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if (l == null) {
l = lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
}
GeoPoint point;
if (l != null) {
int latE6 = (int) (l.getLatitude() * MILLION);
int lonE6 = (int) (l.getLongitude() * MILLION);
point = new GeoPoint(latE6, lonE6);
} else {
point = SAMOIS_SUR_SEINE;
}
mOverlay = new BubbleClickableOverlay(this, point);
mMapView.getOverlays().add(mOverlay);
mController.animateTo(mOverlay.getGeoPoint());
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
GeoPoint point = mOverlay.getGeoPoint();
outState.putInt(Extras.EXTRA_LATITUDE, point.getLatitudeE6());
outState.putInt(Extras.EXTRA_LONGITUDE, point.getLongitudeE6());
}
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
int latitude = savedInstanceState.getInt(Extras.EXTRA_LATITUDE);
int longitude = savedInstanceState.getInt(Extras.EXTRA_LONGITUDE);
GeoPoint point = new GeoPoint(latitude, longitude);
mOverlay.setGeoPoint(point);
mController.animateTo(point);
}
@Override
protected boolean isAutozoomDisplayed() {
return true;
}
@Override
protected boolean isValidateDisplayed() {
return true;
}
@Override
protected void autozoom() {
mController.animateTo(mOverlay.getGeoPoint());
}
@Override
protected void validate() {
GeoPoint point = mOverlay.getGeoPoint();
Location location = new Location("medesmapprovider");
location.setLatitude(point.getLatitudeE6() / (double) MILLION);
location.setLongitude(point.getLongitudeE6() / (double) MILLION);
setResult(RESULT_OK, new Intent().putExtra(Extras.EXTRA_LOCATION, location));
finish();
}
}
|