On 6 Nov., 16:55, Stu <[EMAIL PROTECTED]> wrote:
> Hi Dennis,
>
> is the rest of the source for your application available anywhere? I'd
> be interested to see it.
>
I can't make the whole code available because my application isn't
finished yet and my code looks very ugly currently ;) , but this two
classes should help you:
public class ShowLocation extends MapActivity {
private static final String TAG = "ShowLocation";
public static final int MAIN_MENU_ID = Menu.FIRST;
public static final int GET_CURRENT_LOC_ID = Menu.FIRST + 1;
public static final int REDRAW_MAP_ID = Menu.FIRST + 2;
private MapView mapView;
private MapController mc;
private GeoPoint mDefPoint;
private Bundle extras;
private LocationManager lm;
private GPSListener myGPSListener;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.location_show);
mapView = (MapView) findViewById(R.id.map);
mc = mapView.getController();
extras = getIntent().getExtras();
lm = (LocationManager) getSystemService(LOCATION_SERVICE);
myGPSListener = new GPSListener();
lm.requestLocationUpdates("gps", 0, 0, myGPSListener);
drawMap(false);
}
private void drawMap(boolean animate) {
if (extras != null) {
Double lat = extras.getDouble("lat");
Double lon = extras.getDouble("lon");
if (lat != null && lon != null) {
mDefPoint = new GeoPoint((int) (lat.doubleValue() *
1000000), (int) (lon.doubleValue() * 1000000));
}
} else {
Location tmpLoc = lm.getLastKnownLocation("gps");
if (tmpLoc != null) {
mDefPoint = new GeoPoint((int) (tmpLoc.getLatitude() *
1000000),
(int) (tmpLoc.getLongitude()) * 1000000);
Log.i(TAG, tmpLoc.getLatitude() + " / " +
tmpLoc.getLongitude());
} else {
// Brandenburger Tor in Berlin
// http://www.mygeoposition.com/
mDefPoint = new GeoPoint((int) (52.516269 * 1000000),
(int) (13.377778 * 1000000));
}
}
mc.setZoom(13);
Log.i(TAG, "animate " + animate);
if (animate)
mc.animateTo(mDefPoint);
else
mc.setCenter(mDefPoint);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
boolean result = super.onCreateOptionsMenu(menu);
menu.add(0, MAIN_MENU_ID, 0, R.string.main_menu);
menu.add(0, GET_CURRENT_LOC_ID, 0, R.string.get_current_loc);
menu.add(0, REDRAW_MAP_ID, 0, R.string.redraw_map);
return result;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case MAIN_MENU_ID:
Intent myIntent = new Intent(this, LBSApplication.class);
startActivity(myIntent);
return true;
case GET_CURRENT_LOC_ID:
drawMap(false);
return true;
case REDRAW_MAP_ID:
drawMap(true);
}
return super.onOptionsItemSelected(item);
}
@Override
protected boolean isRouteDisplayed() {
return false;
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_DPAD_UP) {
mc.zoomIn();
return true;
} else if (keyCode == KeyEvent.KEYCODE_DPAD_DOWN) {
mc.zoomOut();
return true;
} else if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT) {
mapView.setTraffic(false);
mapView.setSatellite(true);
return true;
} else if (keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) {
mapView.setSatellite(false);
mapView.setTraffic(true);
return true;
}
return false;
}
}
######################################
public class GPSListener implements LocationListener {
private static final String TAG = "GPSListener";
private Location currentLocation;
public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
Log.i(TAG, "onLocationChanged");
Log.i(TAG, location.getLatitude() + " / " +
location.getLongitude());
currentLocation = location;
}
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
Log.i(TAG, "onProviderDisabled");
}
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
Log.i(TAG, "onProviderEnabled");
}
public void onStatusChanged(String provider, int status, Bundle
extras) {
// TODO Auto-generated method stub
Log.i(TAG, "onStatusChanged");
}
}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---