我在android中的谷歌地图布局上放置了一个精确点,当我导航到第二个布局并返回时,精确点消失了
这是我的 customPinpount 类。
public class CustomPinpoint extends ItemizedOverlay<OverlayItem> {
private ArrayList<OverlayItem> pinpoints = new ArrayList<OverlayItem>();
private Context c;
public CustomPinpoint(Drawable arg0) {
super(boundCenter(arg0));
}
public CustomPinpoint(Drawable m, Context context ) {
this(m);
c = context;
}
@Override
protected OverlayItem createItem(int arg0) {
// TODO Auto-generated method stub
return pinpoints.get(arg0);
}
@Override
public int size() {
// TODO Auto-generated method stub
return pinpoints.size();
}
public void insertPinpoint(OverlayItem item){
pinpoints.add(item);
this.populate();
}
}
这是我的主要活动。
public class Main extends MapActivity {
private static final int REQUEST_CHOOSE_ADDRESS = 0;
private MapView map;
private Touchy t;
private List<Overlay> overlayList;
private long start;
private long stop;
private MyLocationOverlay compass;
private MapController controller;
private int x;
private int y;
private GeoPoint touchedPoint;
private Drawable d;
private Button pinPoint;
private EditText lat;
private EditText lon;
private boolean touched;
private Button dataInter;
private Calculate myRadius;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
setUpView();
}
public void calculateRadiusClicked(View view){
Intent intent = new Intent(getBaseContext(), CalculateRadius.class);
startActivityForResult(intent, REQUEST_CHOOSE_ADDRESS);
}
private void setUpView() {
touched = false;
map = (MapView) findViewById(R.id.themap);
map.setBuiltInZoomControls(true);
t = new Touchy();
overlayList = map.getOverlays();
overlayList.add(t);
compass = new MyLocationOverlay(Main.this, map);
//overlayList.add(compass);
pinPoint = (Button) findViewById(R.id.button2);
dataInter = (Button) findViewById(R.id.button1);
lat = (EditText) findViewById(R.id.editlatitude);
lon = (EditText) findViewById(R.id.editLongitude);
d = getResources().getDrawable(R.drawable.ic_pinpoint);
myRadius = new Calculate();
pinPoint.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
drawPinPoint();
}
});
}
public void drawPinPoint() {
String a = lat.getText().toString();
String b = lon.getText().toString();
if (!a.equals("") && !b.equals("") && touched == true) {
AlertDialog.Builder builder = new AlertDialog.Builder(Main.this);
builder.setMessage("Either click on the map or enter the latitude and longitude \nNot both at the same time");
builder.setCancelable(false);
builder.setNegativeButton("OK",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
AlertDialog alert = builder.create();
alert.show();
} else {
if (a.equals("") && b.equals("") && touched == false) {
AlertDialog.Builder builder = new AlertDialog.Builder(Main.this);
builder.setMessage("Enter latitude and longitude or click on the map");
builder.setCancelable(false);
builder.setNegativeButton("OK",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
dialog.cancel();
}
});
AlertDialog alert = builder.create();
alert.show();
}
else if ((!a.equals("") || !b.equals("")) && touched == false) {
int xx = Integer.parseInt(a);
int yy = Integer.parseInt(b);
touchedPoint = new GeoPoint(xx, yy);
OverlayItem overlayItem = new OverlayItem(touchedPoint,
"What's up", "2nd String");
CustomPinpoint custom = new CustomPinpoint(d, Main.this);
custom.insertPinpoint(overlayItem);
overlayList.add(custom);
controller = map.getController();
controller.animateTo(touchedPoint);
map.invalidate();
//controller.setZoom(6);
} else if ((a.equals("") || b.equals("")) && touched == true) {
OverlayItem overlayItem = new OverlayItem(touchedPoint,
"What's up", "2nd String");
CustomPinpoint custom = new CustomPinpoint(d, Main.this);
custom.insertPinpoint(overlayItem);
overlayList.add(custom);
controller = map.getController();
controller.animateTo(touchedPoint);
//controller.setZoom(6);
}
if (!a.equals("") && !b.equals("") && touched == true) {
touched = false;
}
}
touched = false;
}
@Override
protected void onPause() {
compass.disableCompass();
super.onPause();
}
@Override
protected void onResume() {
compass.enableCompass();
super.onResume();
}
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
class Touchy extends Overlay {
public boolean onTouchEvent(MotionEvent e, MapView m) {
if (e.getAction() == MotionEvent.ACTION_DOWN) {
start = e.getEventTime();
touched = true;
x = (int) e.getX();
y = (int) e.getY();
touchedPoint = map.getProjection().fromPixels(x, y);
}
if (e.getAction() == MotionEvent.ACTION_UP) {
stop = e.getEventTime();
}
return false;
}
}
}
这是我的第二个活动 public class CalculateRadius extends Activity { private Button calculateButton; 私人EditText transmit_power_dbm; 私人 EditText 敏感性编辑;私人EditText TXEdit;私人EditText RXEdit;私人EditText频率编辑;私人 RadioGroup radioGroup;公共计算 cal = new Calculate(); 私有 EditText cellRadius;私有静态最终 int REQUEST_CHOOSE_ADDRESS = 0; 私人主主;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_calculate_radius);
setUpView();
}
private void setUpView() {
calculateButton = (Button) findViewById(R.id.button1);
//main = new Main();
transmit_power_dbm = (EditText)findViewById(R.id.editTxPower);
sencitivityEdit = (EditText) findViewById(R.id.editRxSensitivity);
TXEdit = (EditText) findViewById(R.id.edittxHeight);
RXEdit = (EditText) findViewById(R.id.editRxHeight);
frequencyEdit = (EditText) findViewById(R.id.editFrequency);
radioGroup = (RadioGroup) findViewById(R.id.radioGroup1);
cellRadius = (EditText) findViewById(R.id.EditResult);
calculateButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
pathLoss();
}
});
}
public void plotTheRadius(View view){
Intent intent = new Intent(this, Main.class);
startActivityForResult(intent, REQUEST_CHOOSE_ADDRESS);
this.finish();
}
}