If you mean that you want it to update automatically as the user's
position changes, then you gotta use "Intent".
First call MapView.requestUpdate();
Then register IntentReceiver();
here is some code
static Intent gpsIntent = null;
static IntentReceiver gpsIntentReceiver = null;
static IntentFilter gpsIntentFilter = null;
gpsIntent = new Intent("GPS_ACTION");
locationManager =
(LocationManager)this.getSystemService(Context.LOCATION_SERVICE);
gpsIntentReceiver = new IntentReceiver()
{
public void onReceiveIntent(Context context, Intent intent)
{
Location l = (Location) intent.getExtra("location");
// do something with new location
}
};
gpsIntentFilter = new IntentFilter();
gpsIntentFilter.addAction("GPS_ACTION");
// register IntentReceiver
this.registerReceiver(gpsIntentReceiver, gpsIntentFilter);
On Apr 16, 3:02 pm, [EMAIL PROTECTED] wrote:
> How to update my current location from GPS
> I got the current location from GPS with the following method,
> i want to update the my current location
> any body help me how to do it
>
> // method to get current location from gps
>
> public void gotoCurrentGPSPosition() {
> bubbleIcon = BitmapFactory.decodeResource(getResources(),
> R.drawable.bubble);
> shadowIcon = BitmapFactory.decodeResource(getResources(),
> R.drawable.shadow);
>
> this.myLocationManager = (LocationManager)
> getSystemService(Context.LOCATION_SERVICE);
> mMapView = new MapView(this);
> MapController mc = mMapView.getController();
> currentGPSLocationOfPhone =
> myLocationManager.getCurrentLocation("gps");
> // Create a Point that represents our GPS-Location
> Double lat = this.currentGPSLocationOfPhone.getLatitude() *
> 1E6;
> Double lng = this.currentGPSLocationOfPhone.getLongitude() *
> 1E6;
> // My gps location
> point = new Point(lat.intValue(), lng.intValue());
>
> MapLocationOverlay mylocation = new MapLocationOverlay();
> OverlayController overlaycontrol =
> mMapView.createOverlayController();
> overlaycontrol.add(mylocation, true);
>
> // mc.setFollowMyLocation(true);
> mc.animateTo(point);
> mc.zoomTo(21);
> mMapView.toggleSatellite();
> setContentView(mMapView);
> }
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
Announcing the new M5 SDK!
http://android-developers.blogspot.com/2008/02/android-sdk-m5-rc14-now-available.html
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---