显示对话框,当我在地图上的位置标记的图标点击? [英] Display Dialog Box when i click on the maps place marker icon?
本文介绍了显示对话框,当我在地图上的位置标记的图标点击?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我点击了某个地方在地图android系统中它显示的警告对话框中?要保存的位置到特定列表,例如我的地方或最喜欢的,这样我可以移动的地方,特别列表
先谢谢了......
解决方案
公共类的MapViewer扩展MapActivity {MapView类MapView类;MapController mapController;GeoPoint的mgeoPoint;可绘制标记;MyLocationOverlay mLocationOverlay;MotionEventê;
@覆盖
保护无效的onCreate(捆绑冰柱){ // TODO自动生成方法存根
super.onCreate(冰柱);
的setContentView(R.layout.main); 图形页面=(图形页面)findViewById(R.id.mapView); mapController = mapView.getController(); mapView.setBuiltInZoomControls(真); mapView.setStreetView(真);
标记= getResources()getDrawable(R.drawable.pushpin)。 marker.setBounds(0,0,marker.getIntrinsicWidth(),标记
.getIntrinsicHeight()); 。调用MapView.getOverlays()增加(新MapOverlay(标记));
mLocationOverlay =新MyLocationOverlay(这一点,MapView类);
调用MapView.getOverlays()加(mLocationOverlay)。 setViewLocation();
}
@覆盖
保护对话框onCreateDialog(INT ID){ // TODO自动生成方法存根 开关(ID){
情况下0:
返回新AlertDialog.Builder(本).setTitle(你好)的setIcon(
R.drawable.ic_launcher).setPositiveButton(是,
新OnClickListener(){ @覆盖
公共无效的onClick(DialogInterface对话,诠释它){ // TODO自动生成方法存根 }
})。setCancelable(真).setNegativeButton(取消,
新OnClickListener(){ @覆盖
公共无效的onClick(DialogInterface对话,诠释它){ // TODO自动生成方法存根 }
}) .setOnCancelListener(新OnCancelListener(){ @覆盖
公共无效onCancel(DialogInterface对话){ // TODO自动生成方法存根
Toast.makeText(getApplicationContext(),辞退,
Toast.LENGTH_SHORT).show();
} })。创建();
默认:
打破;
}
返回null;
}
私人无效setViewLocation(){ 的String [] =坐标{22.716221,75.896816}; 双纬度= Double.parseDouble(坐标[0]);
双经度= Double.parseDouble(坐标[1]);
mgeoPoint =新的GeoPoint((INT)(LAT * 1E6),(INT)(LNG * 1E6)); mapController.animateTo(mgeoPoint);
mapController.setZoom(15); mapView.invalidate();}
@覆盖
保护布尔isRouteDisplayed(){ // TODO自动生成方法存根
返回false;
}
点scrPoint;
私人的GeoPoint用GetPoint(双纬度,双LON){ 返回(新的GeoPoint((int)的(纬度* 1E6),(INT)(LON * 1E6)));
}
类MapOverlay扩展
com.google.android.maps.ItemizedOverlay< OverlayItem> { 清单< OverlayItem> ListofGeopoints =新的ArrayList< OverlayItem>();
公共MapOverlay(可绘制defaultMarker){ 超(defaultMarker); ListofGeopoints.add(新OverlayItem(用GetPoint(22.716221,75.896816)
在印度)); 填充(); }
@覆盖
保护布尔中的onTap(INT指数){ 开关(指数){
情况下0:
Toast.makeText(getApplicationContext(),GeoLocation中:0,
Toast.LENGTH_LONG).show();
的ShowDialog(0);
打破;
} 返回true;
}
字符串添加=; 清单<地址> add_List =新的ArrayList<地址>();
私人无效的getAddress(){ add_List = ReverseGeo code
.getFromLocation(35.594227,-105.223618,2); }
@覆盖
保护OverlayItem createItem中(int i)以{
返回(ListofGeopoints.get(ⅰ));
}
@覆盖
公众诠释大小(){
返回ListofGeopoints.size();
}
}
}
When I click the certain place in the map in android it shows the alert Dialog ? You want to save the location into particular list for example My place or Favorite so that I can move that place to particular list in.
Thanks in Advance......
解决方案
public class MapViewer extends MapActivity {
MapView mapView;
MapController mapController;
GeoPoint mgeoPoint;
Drawable marker;
MyLocationOverlay mLocationOverlay;
MotionEvent e;
@Override
protected void onCreate(Bundle icicle) {
// TODO Auto-generated method stub
super.onCreate(icicle);
setContentView(R.layout.main);
mapView = (MapView) findViewById(R.id.mapView);
mapController = mapView.getController();
mapView.setBuiltInZoomControls(true);
mapView.setStreetView(true);
marker = getResources().getDrawable(R.drawable.pushpin);
marker.setBounds(0, 0, marker.getIntrinsicWidth(), marker
.getIntrinsicHeight());
mapView.getOverlays().add(new MapOverlay(marker));
mLocationOverlay = new MyLocationOverlay(this, mapView);
mapView.getOverlays().add(mLocationOverlay);
setViewLocation();
}
@Override
protected Dialog onCreateDialog(int id) {
// TODO Auto-generated method stub
switch (id) {
case 0:
return new AlertDialog.Builder(this).setTitle("Hello").setIcon(
R.drawable.ic_launcher).setPositiveButton("Yes",
new OnClickListener() {
@Override
public void onClick(DialogInterface dialog , int which) {
// TODO Auto-generated method stub
}
}).setCancelable(true).setNegativeButton("Cancel",
new OnClickListener() {
@Override
public void onClick(DialogInterface dialog , int which) {
// TODO Auto-generated method stub
}
})
.setOnCancelListener(new OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "Dismiss",
Toast.LENGTH_SHORT).show();
}
}).create();
default:
break;
}
return null;
}
private void setViewLocation() {
String[] coordinates = { "22.716221", "75.896816" };
double lat = Double.parseDouble(coordinates[0]);
double lng = Double.parseDouble(coordinates[1]);
mgeoPoint = new GeoPoint((int) (lat * 1E6), (int) (lng * 1E6));
mapController.animateTo(mgeoPoint);
mapController.setZoom(15);
mapView.invalidate();
}
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
Point scrPoint;
private GeoPoint getPoint(double lat , double lon) {
return (new GeoPoint((int) (lat * 1E6), (int) (lon * 1E6)));
}
class MapOverlay extends
com.google.android.maps.ItemizedOverlay<OverlayItem> {
List<OverlayItem> ListofGeopoints = new ArrayList<OverlayItem>();
public MapOverlay(Drawable defaultMarker ) {
super(defaultMarker);
ListofGeopoints.add(new OverlayItem(getPoint(22.716221, 75.896816),
"IN", "India"));
populate();
}
@Override
protected boolean onTap(int index) {
switch (index) {
case 0:
Toast.makeText(getApplicationContext(), "GeoLocation : 0",
Toast.LENGTH_LONG).show();
showDialog(0);
break;
}
return true;
}
String add = "";
List<Address> add_List = new ArrayList<Address>();
private void getAddress() {
add_List = ReverseGeocode
.getFromLocation(35.594227, -105.223618, 2);
}
@Override
protected OverlayItem createItem(int i) {
return (ListofGeopoints.get(i));
}
@Override
public int size() {
return ListofGeopoints.size();
}
}
}
这篇关于显示对话框,当我在地图上的位置标记的图标点击?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文