public class LocationMap extends MapActivity {
LocationManager locationManager;
MapView map_view;
ATMDynamicItemizedOverlay atm;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.locationmap);
//add bank button onclick event
ImageView imgView_back=(ImageView)findViewById(R.id.map_imgView_back);
imgView_back.setOnClickListener(new ImageView.OnClickListener()
{
public void onClick(View v){
ViewUtility.NavigateActivate(LocationMap.this,Main.class );
}
});
//set MapControl
map_view =(MapView)findViewById(R.id.map_view);
map_view.setStreetView(true);
map_view.setTraffic(true);
map_view.setBuiltInZoomControls(false);
map_view.setSatellite(false);
List<Overlay> overlays=map_view.getOverlays(); // set location Overlay
MyLocationOverlay mylocationOver=new MyLocationOverlay(this,map_view);
overlays.add(mylocationOver);
mylocationOver.enableCompass();
mylocationOver.enableMyLocation();
//set atm Overlay
atm=new ATMDynamicItemizedOverlay(this.getResources().getDrawable(R.drawable.map_atm));
overlays.add(atm);
String context=Context.LOCATION_SERVICE;
locationManager=(LocationManager)getSystemService(context);
String provider=LocationManager.GPS_PROVIDER;
//OverlayItem a=new OverlayItem(null, provider, provider;
Location location =locationManager.getLastKnownLocation(provider);
if(location!=null)
{
UpdateMapView(location);
}
locationManager.requestLocationUpdates(provider, 10000, 5, locationListener );
}
/* By new location ,update MapWiew's Label */
private void UpdateMapView(Location location)
{
MapController mapcontroller=map_view.getController();
Double lat=location.getLatitude()*1E6;
Double lng=location.getLongitude()*1E6;
GeoPoint point=new GeoPoint(lat.intValue(),lng.intValue());
mapcontroller.setCenter(point);
mapcontroller.setZoom(20);
mapcontroller.animateTo(point);
atm.addNewItem(new GeoPoint(lat.intValue()+1000,lng.intValue()), "marketText", "snippet");
Toast.makeText(this, "lat:" + String.valueOf(lat.intValue())+"lng:"+String.valueOf(lng.intValue()), Toast.LENGTH_SHORT).show();
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if(keyCode == KeyEvent.KEYCODE_BACK){
ViewUtility.NavigateActivate(LocationMap.this, Main.class);
}
return false;
}
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
//create location listener
private LocationListener locationListener = new LocationListener(){
//location is changed
@Override
public void onLocationChanged(Location location) {
UpdateMapView(location);
Log.d("Location", "onLocationChanged");
}
//location is Disable
@Override
public void onProviderDisabled(String provider) {
Log.d("Location", "onProviderDisabled");
}
//location is enabled
@Override
public void onProviderEnabled(String provider) {
Log.d("Location", "onProviderEnabled");
}
//location's status changes
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
Log.d("Location", "onStatusChanged");
}
};
}