i uses seekBar to pass value increase/decrease by user... i put the initial value of barValue=50. when user drag seekbar lesser than current value.. the a,b decreases by 0.00001.
Problem i face. its only do the IF condition onced. after seekBar updated.. no changes on a and b.
public static double a,b;
public static int barValue;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
// Define the criteria how to select the locatioin provider -> use
// default
Criteria criteria = new Criteria();
provider = locationManager.getBestProvider(criteria, false);
Location location = locationManager.getLastKnownLocation(provider);
a= location.getLatitude();
b= location.getLongitude();
bar = (SeekBar)findViewById(R.id.seekBar1); // make seekbar object
bar.setOnSeekBarChangeListener(this); // set seekbar listener.
barValue = 50;
bar.setProgress(barValue);
}
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
// TODO Auto-generated method stub
if (progress > barValue)
{
a += seekBar.getProgress()/10000;
b += seekBar.getProgress()/10000;
getSensorManager().enableMockLocation(a, b);
}
else if(progress < barValue)
{
a -= seekBar.getProgress()/10000;
b -= seekBar.getProgress()/10000;
getSensorManager().enableMockLocation(a, b);
}
}
#Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
#Override
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
seekBar.setSecondaryProgress(seekBar.getProgress());
barValue = seekBar.getProgress();
}
Related
In my app i have to apply resize using seekbar to selected image onclick but problem is that only last applied stickerview can be resized and if i want to resize the previous stickerview then also last sticker is being resized.
Can anyone help me with this problem
holder.icon.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (a == 1) {
canvas.setBackgroundResource(mThumbIds[position]);
dialog.dismiss();
a = 0;
}
if (a1 == 1) {
Gallery gallery = (Gallery) findViewById(R.id.gallery);
gallery.setSpacing(1);
final GalleryImageAdapter galleryImageAdapter= new GalleryImageAdapter(getApplicationContext(),position);
gallery.setAdapter(galleryImageAdapter);
gallery.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
iv_sticker1 = new StickerImageView(MainActivity2.this);
if(x ==1)
iv_sticker1.setImageResource(galleryImageAdapter.mImageIds[position]);
if(x ==2)
iv_sticker1.setImageResource(galleryImageAdapter.mImageIds1[position]);
if(x ==3)
iv_sticker1.setImageResource(galleryImageAdapter.mImageIds2[position]);
canvas.addView(iv_sticker1);
}
});
a1 = 0;
}
if (a2 == 1) {
iv_sticker1 = new StickerImageView(MainActivity2.this);
iv_sticker1.setImageDrawable(getResources().getDrawable(mThumbIds2[position]));
canvas.addView(iv_sticker1);
iv_sticker1.setOwnerId(2);
dialog.dismiss();
a2 = 0;
}
if (a3 == 1) {
iv_sticker1 = new StickerImageView(MainActivity2.this);
iv_sticker1.setImageDrawable(getResources().getDrawable(mThumbIds3[position]));
canvas.addView(iv_sticker1);
dialog.dismiss();
a3 = 0;
}
}
});
And this is my resize program
final SeekBar sk1 = (SeekBar) findViewById(R.id.seekBar1);
sk1.setMax(500);
sk1.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
// TODO Auto-generated method stub
iv_sticker1.getMainView();
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(progress, progress);
iv_sticker1.setLayoutParams(params);
iv_sticker1.setMinimumWidth(progress);
iv_sticker1.setMinimumHeight(progress);
}
});
Now whenever i do this only last iv_sticker1 get selected.How can i apply resize to selected image on click?
I am working on a game. Its all working well, the only thing I need is for my animation to pause when I press the home or on/off button on my phone. As far as I log correct, the pause script (as found here) works well. It keeps incrementing the time and applies it to the animation. However when I resume my game, the animations all resume on the left side of the screen instead of the position it originally was in when I paused it in. This is my stripped code. I really hope someone can help me.
public class GameView extends Activity{
ImageView peanut;
TranslateAnim movePeanut;
AnimationSet animSet = new AnimationSet(true);
#SuppressLint("NewApi")
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.gameviewlayout);
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int width = size.x;
movePeanut = new TranslateAnim(width,0,0,0);
movePeanut.setDuration(5000);
movePeanut.setRepeatCount(-1);
movePeanut.setRepeatMode(Animation.REVERSE);
animSet.addAnimation(movePeanut);
animSet.setFillAfter(true);
peanut = (ImageView) findViewById(R.id.imgview1);
peanut.startAnimation(animSet);
#Override
protected void onStart() {
// TODO Auto-generated method stub
super.onStart();
}
#Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
movePeanut.resume();
}
#Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
movePeanut.pause();
}
#Override
protected void onStop() {
// TODO Auto-generated method stub
super.onStop();
}
public void finish (){
Intent intent = new Intent (GameView.this, MainActivity.class);
startActivity(intent);
}
public class TranslateAnim extends TranslateAnimation{
public TranslateAnim(float fromXDelta, float toXDelta, float fromYDelta,
float toYDelta) {
super(fromXDelta, toXDelta, fromYDelta, toYDelta);
// TODO Auto-generated constructor stub
}
private long mElapsedAtPause=0;
private boolean mPaused=false;
#Override
public boolean getTransformation(long currentTime, Transformation outTransformation) {
if(mPaused && mElapsedAtPause==0) {
mElapsedAtPause=currentTime-getStartTime();
}
if(mPaused)
setStartTime(currentTime-mElapsedAtPause);
boolean returnValue = super.getTransformation(currentTime, outTransformation);
return returnValue;
}
public void pause() {
mElapsedAtPause=0;
mPaused=true;
}
public void resume() {
mPaused=false;
}
}
}
How can i make this app run in the background? I can't implement Service class because i already using MapActivity. What should i do?
public class GoogleMaps extends MapActivity implements LocationListener {
LocationManager locationManager;
MapView map;
long start;
long stop;
MyLocationOverlay myLocation;
MapController controller;
List<Overlay> overlayList;
int x, y;
GeoPoint touchedPoint;
Drawable d;
String towers;
int lat;
int longi;
double midllat;
double midlongi;
NotificationManager nm;
static final int uniqueID = 1394885;
// Location location;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.googlemaps);
map = (MapView) findViewById(R.id.mvGoogleMaps);
ourLocation();
Touchy t = new Touchy();
overlayList = map.getOverlays();
overlayList.add(t);
d = getResources().getDrawable(R.drawable.round_pointer);
controller.setZoom(18);
Criteria crit = new Criteria();
towers = locationManager.getBestProvider(crit, false);
Location location = locationManager.getLastKnownLocation(towers);
nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
nm.cancel(uniqueID);
}
public void ourLocation()
{
// Pin der blinker på lokation
myLocation = new MyLocationOverlay(this, map);
map.getOverlays().add(myLocation);
myLocation.enableMyLocation();
// Fin nuværende lokation
locationManager = (LocationManager) this
.getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,
20000, 0, this);
controller = map.getController();
}
There is more code here, but nothing relevant to this case. Just a feature that lets me pin a point.
#Override
protected void onPause() {
// TODO Auto-generated method stub
myLocation.disableCompass();
super.onPause();
locationManager.removeUpdates(this);
}
#Override
protected void onResume() {
// TODO Auto-generated method stub
myLocation.enableCompass();
super.onResume();
locationManager.requestLocationUpdates(towers, 500, 1, this);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
#Override
protected boolean isRouteDisplayed() {
return false;
}
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
public void onLocationChanged(Location location1) {
// TODO Auto-generated method stub
// Updating location and zoom
controller.setCenter(new GeoPoint(
(int) (location1.getLatitude() * 1000000), (int) (location1
.getLongitude() * 1000000)));
controller.setZoom(18);
// Trying to get MyPostion.
Location myLocation = new Location("point A");
myLocation.setLongitude(location1.getLongitude());
myLocation.setLatitude(location1.getLatitude());
Location locationB = new Location("point B");
locationB.setLatitude(midllat);
locationB.setLongitude(midlongi);
float distance = myLocation.distanceTo(locationB);
if (distance < 100) {
String hej = formatDist(distance);
AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
am.setRingerMode(AudioManager.RINGER_MODE_SILENT);
Intent intent = new Intent(this, GoogleMaps.class);
PendingIntent pi = PendingIntent.getActivity(this, 0, intent, 0);
String body = "You are now in the silentzone";
String title = "IRemember";
Notification n = new Notification(R.drawable.round_pointer, body,
System.currentTimeMillis());
n.setLatestEventInfo(this, title, body, pi);
n.defaults = Notification.DEFAULT_ALL;
nm.notify(uniqueID, n);
}
}
public String formatDist(float meters) {
if (meters < 1000) {
return ((int) meters) + "m";
} else
return formatDec(meters / 1000f, 1) + "km";
}
public String formatDec(float val, int dec) {
int factor = (int) Math.pow(10, dec);
int front = (int) (val);
int back = (int) Math.abs(val * (factor)) % factor;
return front + "." + back;
}
}
I am currently showing marker on my current location whenever the current location gets changed. And the below code works fine. But the problem with this is,- Suppose for the first time I passed some location and my marker will be there at that position but the second time if I pass any other different location then my marker will be there in second location but at the same time my marker also stays in First Location too and I don't want this thing. I only need whenever the Current Location changes all other marker should gets disappeared, only the current location marker should be there. Hope I am clear to everyone
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mapView = (MapView) findViewById(R.id.mapView);
mapView.setBuiltInZoomControls(true);
mapController = mapView.getController();
mapController.setZoom(15);
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0,
0, new GeoUpdateHandler());
}
public class GeoUpdateHandler implements LocationListener {
#Override
public void onLocationChanged(Location location) {
int lat = (int) (location.getLatitude() * 1E6);
int lng = (int) (location.getLongitude() * 1E6);
Drawable marker=getResources().getDrawable(android.R.drawable.star_big_on);
int markerWidth = marker.getIntrinsicWidth();
int markerHeight = marker.getIntrinsicHeight();
marker.setBounds(0, markerHeight, markerWidth, 0);
myItemizedOverlay = new MyItemizedOverlay(marker);
mapView.getOverlays().add(myItemizedOverlay);
GeoPoint point = new GeoPoint(lat, lng);
myItemizedOverlay.addItem(point, "myPoint1", "myPoint1");
mapController.animateTo(point);
String address = ConvertPointToLocation(point);
Toast.makeText(getBaseContext(), address, Toast.LENGTH_SHORT).show();
mapView.invalidate();
}
}
Below is my ItemizedOverlay class-
public class MyItemizedOverlay extends ItemizedOverlay<OverlayItem>{
private ArrayList<OverlayItem> overlayItemList = new ArrayList<OverlayItem>();
public MyItemizedOverlay(Drawable marker) {
super(boundCenterBottom(marker));
// TODO Auto-generated constructor stub
populate();
}
public void addItem(GeoPoint p, String title, String snippet){
OverlayItem newItem = new OverlayItem(p, title, snippet);
overlayItemList.add(newItem);
populate();
}
#Override
protected OverlayItem createItem(int i) {
// TODO Auto-generated method stub
return overlayItemList.get(i);
}
#Override
public int size() {
// TODO Auto-generated method stub
return overlayItemList.size();
}
public void clear() {
overlayItemList.clear();
populate();
}
#Override
public void draw(Canvas canvas, MapView mapView, boolean shadow) {
// TODO Auto-generated method stub
super.draw(canvas, mapView, shadow);
//boundCenterBottom(marker);
}
}
you just have to remove previously added items before adding the new one
public void addItem(GeoPoint p, String title, String snippet){
OverlayItem newItem = new OverlayItem(p, title, snippet);
overlayItemList.removeAll();
overlayItemList.add(newItem);
populate();
}
I am developing an android application that contains 3 activities and one of them is map. I am using google maps
what I want:
When the user opens the activity (map) it shows the user her location not the coordinate.
The user should also be able to posit(pining) any place by using a pin and my app must store the coordinates for this pin in a variable so i can use it later.
public class LActivity extends MapActivity
{
/** Called when the activity is first created. */
MapView mapView;
GeoPoint geo;
MapController mapController;
LocationManager locationManager;
CustomPinpoint itemizedoverlay;
#Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mapView = (MapView) findViewById(R.id.mapView);
// create a map view
//LinearLayout linearLayout = (LinearLayout) findViewById(R.id.main);
mapView.setBuiltInZoomControls(true);
// Either satellite or 2d
mapView.setSatellite(true);
mapController = mapView.getController();
mapController.setZoom(14); // Zoon 1 is world view
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, new GeoUpdateHandler());
Drawable drawable = this.getResources().getDrawable(R.drawable.point);
itemizedoverlay = new CustomPinpoint(drawable);
createMarker();
}
public class GeoUpdateHandler implements LocationListener {
#Override
public void onLocationChanged(Location location) {
int lat = (int) (location.getLatitude() * 1E6);
int lng = (int) (location.getLongitude() * 1E6);
GeoPoint point = new GeoPoint(lat, lng);
createMarker();
mapController.animateTo(point); // mapController.setCenter(point);
}
#Override
public void onProviderDisabled(String provider) {
}
#Override
public void onProviderEnabled(String provider) {
}
#Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
}
private void createMarker() {
GeoPoint p = mapView.getMapCenter();
OverlayItem overlayitem = new OverlayItem(p, "", "");
itemizedoverlay.addOverlay(overlayitem);
mapView.getOverlays().add(itemizedoverlay);
}
#Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
}
this is CustomPinpoint class
public class CustomPinpoint extends ItemizedOverlay<OverlayItem> {
static int maxNum = 3;
OverlayItem overlays[] = new OverlayItem[maxNum];
int index = 0;
boolean full = false;
CustomPinpoint itemizedoverlay;
public CustomPinpoint(Drawable defaultMarker) {
super(boundCenterBottom(defaultMarker));
}
#Override
protected OverlayItem createItem(int i) {
return overlays[i];
}
#Override
public int size() {
if (full) {
return overlays.length;
} else {
return index;
}
}
public void addOverlay(OverlayItem overlay) {
if (index < maxNum) {
overlays[index] = overlay;
} else {
index = 0;
full = true;
overlays[index] = overlay;
}
index++;
populate();
}
}
I have implemented the same thing you want. I am providing you the sample code. In this I have also implemented the ProgressDialog when fetching the location.
This is the starting point for getting the location. I named this AndroidLocationActivity. This is the 1st activity which starts when your app starts.
String provider;
public double latitude, longitude = 0;
CurrentPositionTask getCurrentLocation;
Location currentLocation;
LocationListener locationListener;
LocationManager locationManager;
private long time=0;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
try {
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
setCriteria();
currentLocation = AndroidLocationActivity.this.locationManager.getLastKnownLocation(provider);
if (currentLocation == null) {
currentLocation = new Location(provider);
}
time = currentLocation.getTime();
if (latitude == 0 && longitude == 0) {
latitude = currentLocation.getLatitude();
longitude = currentLocation.getLongitude();
}
Toast.makeText(AndroidLocationActivity.this, String.valueOf(time), Toast.LENGTH_LONG).show();
Here set the time if time is not more than 1minute than i am not updating the location.
if (time >= 100000) {
latitude = 0;
longitude = 0;
}
} catch (NullPointerException e) {
// TODO: handle exception
System.out.println("Null");
e.printStackTrace();
}
catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
runAsyncTask();
}
#Override
protected void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
locationManager.removeUpdates(locationListener);
}
public void setCriteria() {
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
criteria.setAltitudeRequired(false);
criteria.setBearingRequired(false);
criteria.setCostAllowed(true);
criteria.setPowerRequirement(Criteria.POWER_MEDIUM);
provider = locationManager.getBestProvider(criteria, true);
Toast.makeText(getApplicationContext(), "Provider - " + provider, Toast.LENGTH_SHORT).show();
if (provider == null) {
provider = LocationManager.GPS_PROVIDER;
}
}
public void runAsyncTask() {
// TODO Auto-generated method stub
if (getCurrentLocation == null) {
getCurrentLocation = new CurrentPositionTask();
}
if (getCurrentLocation != null) {
getCurrentLocation.execute("Searching for Location");
}
}
public boolean checkConnection()
{
//ARE WE CONNECTED TO THE NET
ConnectivityManager conMgr = (ConnectivityManager) getSystemService (AndroidLocationActivity.CONNECTIVITY_SERVICE);
if (conMgr.getActiveNetworkInfo() != null && conMgr.getActiveNetworkInfo().isAvailable()&& conMgr.getActiveNetworkInfo().isConnected()) {
return true;
} else {
return false;
}
}
private class CurrentPositionTask extends AsyncTask<String, Void, Void>
{
private ProgressDialog Dialog = new ProgressDialog(AndroidLocationActivity.this);
private boolean flag = true;
public CurrentPositionTask() {
locationListener = new MyLocationListener();
}
#Override
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
try {
if (checkConnection()) {
Dialog.setTitle("Loading");
Dialog.setMessage("Searching for Location");
Dialog.show();
locationManager.requestLocationUpdates(provider, 0, 0, locationListener);
}
else {
Toast.makeText(getApplicationContext(), "Internet is Not Available", Toast.LENGTH_LONG).show();
}
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
#Override
protected Void doInBackground(String... params) {
// TODO Auto-generated method stub
while (flag) {
if (latitude !=0 && longitude != 0) {
flag=false;
}
}
return null;
}
#Override
protected void onPostExecute(Void result) {
// TODO Auto-generated method stub
Toast.makeText(AndroidLocationActivity.this, "Location Floats:- " + latitude + "," + longitude, Toast.LENGTH_LONG).show();
super.onPostExecute(result);
if (Dialog != null && Dialog.isShowing()) {
Dialog.dismiss();
time=0;
Intent homeIntent = new Intent(AndroidLocationActivity.this.getApplicationContext(), HomeMenuActivity.class);
set the lat & lng here and start new activity
homeIntent.putExtra("lat", latitude);
homeIntent.putExtra("lng", longitude);
startActivity(homeIntent);
}
locationManager.removeUpdates(locationListener);
}
}
class MyLocationListener implements LocationListener {
#Override
public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
if (location != null) {
latitude = location.getLatitude();
longitude = location.getLongitude();
}
}
#Override
public void onProviderDisabled(String arg0) {
// TODO Auto-generated method stub
Toast.makeText( getApplicationContext(),"Gps Disabled",Toast.LENGTH_SHORT).show();
}
#Override
public void onProviderEnabled(String arg0) {
// TODO Auto-generated method stub
Toast.makeText( getApplicationContext(),"Gps Enabled",Toast.LENGTH_SHORT).show();
}
#Override
public void onStatusChanged(String arg0, int arg1, Bundle arg2) {
// TODO Auto-generated method stub
}
}
This is the function in which i am displaying the Map. This is the HomeMenuActivity
public static Context context;
onCreate(..) {
context = getApplicationContext(); // it will be used in Itemized Overlay
latitude = getIntent().getDoubleExtra("lat", 0);//get the lat & lng
longitude = getIntent().getDoubleExtra("lng", 0);
}
public void showMap() {
// TODO Auto-generated method stub
try {
geoPoint = new GeoPoint((int)(latitude * 1E6),(int)(longitude * 1E6));
mapview = (MapView)findViewById(R.id.mapview);
mapControll= mapview.getController();
mapview.setBuiltInZoomControls(true);
mapview.setStreetView(true);
mapview.setTraffic(true);
mapControll.setZoom(16);
mapControll.animateTo(geoPoint);
userPic = this.getResources().getDrawable(your pic....);
userPicOverlay = new MyItemizedOverlay(userPic);
OverlayItem overlayItem = new OverlayItem(geoPoint, "", null);
userPicOverlay.addOverlay(overlayItem);
mapview.getOverlays().add(userPicOverlay);
//Added symbols will be displayed when map is redrawn so force redraw now
mapview.postInvalidate();
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
ItemizedOverlay Class
public class MyItemizedOverlay extends ItemizedOverlay<OverlayItem> {
private ArrayList<OverlayItem> myOverlays ;
public MyItemizedOverlay(Drawable defaultMarker) {
super(boundCenterBottom(defaultMarker));
myOverlays = new ArrayList<OverlayItem>();
populate();
}
public void addOverlay(OverlayItem overlay){
myOverlays.add(overlay);
populate();
}
#Override
protected OverlayItem createItem(int i) {
return myOverlays.get(i);
}
// Removes overlay item i
public void removeItem(int i){
myOverlays.remove(i);
populate();
}
// Returns present number of items in list
#Override
public int size() {
return myOverlays.size();
}
public void addOverlayItem(OverlayItem overlayItem) {
myOverlays.add(overlayItem);
populate();
}
public void addOverlayItem(int lat, int lon, String title) {
try {
GeoPoint point = new GeoPoint(lat, lon);
OverlayItem overlayItem = new OverlayItem(point, title, null);
addOverlayItem(overlayItem);
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
#Override
protected boolean onTap(int index) {
// TODO Auto-generated method stub
String title = myOverlays.get(index).getTitle();
Toast.makeText(HomeMenuActivity.context, title, Toast.LENGTH_LONG).show();
return super.onTap(index);
}
}
Hope this will help.....
Remove your method onCreate and add this code:
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.map);
initMap(); // This is the method which initialize the map
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0,
0, new GeoUpdateHandler());
Drawable drawable = this.getResources().getDrawable(R.drawable.point);
itemizedoverlay = new CustomPinpoint(drawable);
createMarker();
}
#Override
public void onResume()
{
super.onResume();
try
{
initMyLocation();
}catch(Exception e){}
}
/**
* Inits the map.
*/
protected void initMap()
{
mapView = (MyMapView) findViewById(R.id.mapView);
mapView.setBuiltInZoomControls(true);
mapView.setSatellite(true);
mapView.setStreetView(false);
mapController = mapView.getController();
mapOverlay = new MapOverlay();
List<Overlay> overlays = mapView.getOverlays();
overlays.add(mapOverlay);
mapController.setZoom(14);
mapView.invalidate();
}
/**
* Initialises the MyLocationOverlay and adds it to the overlays of the map.
*/
public void initMyLocation() {
try
{
LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Location l = LocationService.getLastKnownLocation(lm);
int lat = (int)(l.getLatitude()*1E6);
int lng = (int)(l.getLongitude()*1E6);
mapController.setCenter(new GeoPoint(lat , lng));
myLocOverlay = new MyLocationOverlay(this, mapView);
myLocOverlay.enableMyLocation();
mapView.getOverlays().add(myLocOverlay);
mapController.setCenter(myLocOverlay.getMyLocation());
}catch(NullPointerException e){}
findMe();
}
/**
* This method will animate to my current position
*/
public void findMe()
{
try
{
mapController.animateTo(myLocOverlay.getMyLocation());
}catch(NullPointerException e){}
}
Then to store the Overlays for future use you can either use SharedPreferences or SQLite. There are loads of tutorials for each of them.