我有一个mapView类和一个StoreFinder类。我希望能够按下AlertDialog中的按钮,该按钮包含地理点值经度和纬度。我希望它在我的MapView中显示经度和纬度值的位置。
简单:
按经度和纬度按钮IN ALERTDIALOG - > MapView显示位置。
我将如何做到这一点?
感谢您充裕的时间。
CODE:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.storefinder_bars);
sirius();
}
public void sirius() {
ImageButton hoursButton = (ImageButton) findViewById(R.id.hours);
ImageButton addressButton = (ImageButton) findViewById(R.id.address);
//ImageButton phoneButton = (ImageButton) findViewById(R.id.phone);
final AlertDialog.Builder siriushours = new AlertDialog.Builder(this);
hoursButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
siriushours.setTitle("Opening Hours");
siriushours.setMessage(
"\n---Monday---\n" + "CLOSED"
+ "\n\n---Tuesday---\n" + "CLOSED"
+ "\n\n---Wednesday---\n" + "22:00 - 3:00"
+ "\n\n---Thursday---\n" + "CLOSED"
+ "\n\n---Friday---\n" + "22:00 - 3:00"
+ "\n\n---Saturday---\n" + "22:00 - 3:00"
+ "\n\n---Sunday---\n" + "CLOSED");
siriushours.setPositiveButton("OK",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
dialog.dismiss();
}
});
siriushours.show();
}
});
//ADDRESS
final AlertDialog.Builder siriusadd = new AlertDialog.Builder(this);
addressButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
siriusadd.setTitle("Address");
siriusadd.setMessage(
"33 Belvoir Street, Leicester , LE1 6SL");
siriusadd.setPositiveButton("Show On Map",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
}
});
siriusadd.setNegativeButton("Route",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("http://maps.google.com/maps?daddr="+52.63274+","+-1.13145));
startActivity(intent);
}
});
siriusadd.show();
}
});
}
我想在这里找到积极的按钮:“siriusadd.setPositiveButton(”在地图上显示“,”允许我从AlertDialog跳转到我的MapView地理坐标。如果没有,我有气球逐项布局,我有标记到位。我更愿意,如果他们会跳转到那个。但是,地理点会做。
为所有帮助干杯。
答案 0 :(得分:1)
使用MapController
为所需的地理位置设置动画。
为MapController
MapView
private MapController mc;
mc = mapView.getController();
初始化按钮的对话框onClickListener
后(这里是正按钮的示例:
dialog.setPositiveButton(mContext.getString(R.string.photo), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
mc.animateTo(geoPoint);
}
});
答案 1 :(得分:0)
只需使用putExtra调用intent:
siriusadd.setPositiveButton("Show On Map",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
Intent myIntent = new Intent(getApplicationContext(),
MyMapActivity.class);
myIntent.putExtra("id", anId);
// add any additional informations with other key values
// (latitude or longitude)
startActivityForResult(myIntent, 0);
}
});
将地图活动的onResume方法中的这些信息添加到地图活动中并相应地设置地图视图:
@Override
protected void onResume() {
super.onResume();
Intent intent = getIntent();
if (intent.getStringExtra("id") == null) {
// your map logic goes here
}
}