In the article Read GPS location, LocationManager described how to get current location from GPS.
In the article A minimal Map application using MapActivity, described how to implemented a MapView with MapActiity.
In this article, both exercises are merged to have a MapView, which will center in the current location from GPS.

Please note that the application cannot be run directly, you have to have your own API Key to using the GPS API. Refer to the article A minimal Map application using MapActivity to obtain API Key.
Modify AndroidManifest.xml:
Add as a child of the element.
Add
and as children of the element.
Modify main.xml to have a MapView
Finally, modify AndroidLocation.java
Download the files.
Also refer Enable "Use wireless networks" and "Use GPS satellites" in Android Emulator and Change GPS location of Android Emulator.
In the article A minimal Map application using MapActivity, described how to implemented a MapView with MapActiity.
In this article, both exercises are merged to have a MapView, which will center in the current location from GPS.

Please note that the application cannot be run directly, you have to have your own API Key to using the GPS API. Refer to the article A minimal Map application using MapActivity to obtain API Key.
Modify AndroidManifest.xml:
Add
Add
and
package="com.AndroidLocation"
android:versionCode="1"
android:versionName="1.0">
android:label="@string/app_name">
Modify main.xml to have a MapView
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
android:id="@+id/longitude"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="Longitude:"
/>
android:id="@+id/latitude"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="Latitude:"
/>
android:id="@+id/mapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="false"
android:apiKey="-----Your Own API Key here-------------"
/>
Finally, modify AndroidLocation.java
package com.AndroidLocation;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.widget.TextView;
public class AndroidLocation extends MapActivity {
private LocationManager myLocationManager;
private LocationListener myLocationListener;
private TextView myLongitude, myLatitude;
private MapView myMapView;
private MapController myMapController;
private void CenterLocatio(GeoPoint centerGeoPoint)
{
myMapController.animateTo(centerGeoPoint);
myLongitude.setText("Longitude: "+
String.valueOf((float)centerGeoPoint.getLongitudeE6()/1000000)
);
myLatitude.setText("Latitude: "+
String.valueOf((float)centerGeoPoint.getLatitudeE6()/1000000)
);
};
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
myMapView = (MapView)findViewById(R.id.mapview);
myLongitude = (TextView)findViewById(R.id.longitude);
myLatitude = (TextView)findViewById(R.id.latitude);
myMapView.setSatellite(true); //Set satellite view
myMapController = myMapView.getController();
myMapController.setZoom(20); //Fixed Zoom Level
myLocationManager = (LocationManager)getSystemService(
Context.LOCATION_SERVICE);
myLocationListener = new MyLocationListener();
myLocationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER,
0,
0,
myLocationListener);
//Get the current location in start-up
GeoPoint initGeoPoint = new GeoPoint(
(int)(myLocationManager.getLastKnownLocation(
LocationManager.GPS_PROVIDER)
.getLatitude()*1000000),
(int)(myLocationManager.getLastKnownLocation(
LocationManager.GPS_PROVIDER)
.getLongitude()*1000000));
CenterLocatio(initGeoPoint);
}
private class MyLocationListener implements LocationListener{
public void onLocationChanged(Location argLocation) {
// TODO Auto-generated method stub
GeoPoint myGeoPoint = new GeoPoint(
(int)(argLocation.getLatitude()*1000000),
(int)(argLocation.getLongitude()*1000000));
CenterLocatio(myGeoPoint);
}
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
public void onStatusChanged(String provider,
int status, Bundle extras) {
// TODO Auto-generated method stub
}
}
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
};
}
Also refer Enable "Use wireless networks" and "Use GPS satellites" in Android Emulator and Change GPS location of Android Emulator.
Because te application read location in start-up,
so you have to send GPS Location to Android Emulator
at least once before the application start.
Edited@11-11-2009