public class MainActivity extends MapActivity {
LocationManager locmang;
static MapController mcon;
GeoPoint geo;
static GeoPoint point;
static MapView myMap;
MyLocationOverlay comp;
static double lat =0;
static double loni =0;
private LocationManager locManager;
private LocationListener locListener;
List<Overlay>mapOverlays;
Drawable drawable;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
myMap= (MapView)findViewById(R.id.mapview);
myMap.displayZoomControls(true);
myMap.setBuiltInZoomControls(true);
mcon=myMap.getController();
myMap.setSatellite(false);
geo = new GeoPoint((int)(lat*1E6),(int)(loni*1E6));
mcon.setCenter(geo);
mcon=myMap.getController();
mcon.animateTo(geo);
comp = new MyLocationOverlay(this, myMap);
myMap.getOverlays().add(comp);
LocationManager lm =(LocationManager)getSystemService(Context.LOCATION_SERVICE);
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER,10, 100, (LocationListener) this);
mapOverlays = myMap.getOverlays();
MapOverlay mapOverlay = new MapOverlay();
List<Overlay> listOfOverlays = myMap.getOverlays();
listOfOverlays.clear();
listOfOverlays.add(mapOverlay);
myMap.invalidate();
Intent startService = new Intent(getApplicationContext(),ServiceLocation.class);
startService(startService);
}
public static void updateMap() {
if(ServiceLocation.curLocation!=null){
lat = ServiceLocation.curLocation.getLatitude();
loni = ServiceLocation.curLocation.getLongitude();
if(myMap!=null){
point = new GeoPoint((int)(lat*1e6),(int)(loni*1e6));
mcon.animateTo(point);
myMap.invalidate();
}
}
}
public void createAndShowMyItemizedOverlay(Location newLocation) {
List<Overlay> overlays = myMap.getOverlays();
if (overlays.size() > 0) {
for (Iterator<Overlay> iterator = overlays.iterator(); iterator.hasNext();) {
iterator.next();
iterator.remove();
}
}
GeoPoint geopoint = new GeoPoint(
(int) (newLocation.getLatitude() * 1E6), (int) (newLocation
.getLongitude() * 1E6));
Drawable icon = getResources().getDrawable(R.drawable.image19);
icon.setBounds(0, 0, icon.getIntrinsicWidth(), icon
.getIntrinsicHeight());
myMap.getController().animateTo(geopoint);
myMap.postInvalidate();
}
@Override
protected boolean isRouteDisplayed() {
return false;
}
public class MapOverlay extends Overlay {
public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) {
super.draw(canvas, mapView, shadow);
if(!shadow){
Point screenPts = new Point();
if(lat==0 && loni==0)
mapView.getProjection().toPixels(geo, screenPts);
else{
mapView.getProjection().toPixels(point, screenPts);
}
Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.image19);
canvas.drawBitmap(bmp, screenPts.x, screenPts.y-50, null);
}
return true;
}
}
}`