i write a map viewer and i want to get Latitude and Longitude from user, then show him the location.
i use menu for this work. but i don’t know how show him something to enter the values. this is my code.
public class main extends MapActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
MapView view = (MapView) findViewById(R.id.themap);
view.setBuiltInZoomControls(true);
final MapController control = view.getController();
LocationManager manager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
LocationListener listener = new LocationListener() {
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
@Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onLocationChanged(Location location) {
control.setCenter(new GeoPoint((int)location.getLatitude(), (int)location.getLongitude()));
}
};
manager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, listener);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
return super.onOptionsItemSelected(item);
}
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
}
so i have 2 questions. first how can i create a menu for my locations. i must use context menu or something else.
second, if i get locations, i can enter them directly to my Latitude and Longitude?
in my code i use the default location of user.
Well if I am understanding you correctly you can do this 2 ways.
1) In your xml layout add an input box and button then on click set your location.
2) Override your onTouch and have and alert box pop up and ask for the long and lat. Then set it accordingly.
Both these will be setting your overLay: http://developer.android.com/resources/tutorials/views/hello-mapview.html
one of many overlay tutorials: http://eagle.phys.utk.edu/guidry/android/mapOverlayDemo.html