本文介绍了ONTAP()在地图上的事件,不会触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,我无法火灾ONTAP()事件
我想添加一个标记,每当我在地图上点击,当我在另一个GeoPoint的挖掘第一标记应该会消失,标记应在新的位置添加...
到现在我来到了这个point..can有人告诉我我要去哪里错了!
在此先感谢
来源$ C $ C
公共类的getLocation扩展MapActivity实现OnClickListener {MapView类MapView类; MapController MC; GeoPoint的磷;
INT范围;
串类;
按钮来查看,交通;
私有静态最后的字符串标记=类的getLocation;
ZoomControls zoomControls;
帆布油画;
MapOverlay itemizedoverlay;
清单<&叠加GT; mapOverlays; 公共无效的onCreate(捆绑savedInstanceState){
super.onCreate(savedInstanceState);
Log.d(变量,里面的onCreate);
的setContentView(R.layout.main);
图形页面=(图形页面)findViewById(R.id.myMapView1);
的LinearLayout变焦=(的LinearLayout)findViewById(R.id.zoom);
mapView.setReticleDrawMode(
MapView.ReticleDrawMode.DRAW_RETICLE_UNDER);
//可绘制可绘制= this.getResources()getDrawable(R.drawable.mark)。
鉴于=(按钮)findViewById(R.id.BtnView);
流量=(按钮)findViewById(R.id.BtnTraffic);
捆绑额外= getIntent()getExtras()。
如果(额外!= NULL)
{
类别= extra.getString(类);
范围= extra.getInt(范围);
}
view.setOnClickListener(本);
traffic.setOnClickListener(本);
zoomControls =(ZoomControls)findViewById(R.id.zoomcontrols);
zoomControls.setOnZoomInClickListener(新View.OnClickListener(){
@覆盖
公共无效的onClick(视图v){
mc.zoomIn();
}
});
zoomControls.setOnZoomOutClickListener(新View.OnClickListener(){
@覆盖
公共无效的onClick(视图v){
mc.zoomOut();
}
});
mapOverlays =调用MapView.getOverlays();
可绘制可绘制= this.getResources()getDrawable(R.drawable.mark)。
itemizedoverlay =新MapOverlay(绘制,这一点);
MC = mapView.getController();
mapView.invalidate();
mc.setZoom(17);
mapView.invalidate();
// mapView.setSatellite(真);
mapView.setStreetView(真);
// mapView.setOnClickListener(本);
Log.d(变量,退出的onCreate);
}
类MapOverlay扩展com.google.android.maps.ItemizedOverlay< OverlayItem>
{ 私人的ArrayList< OverlayItem> mOverlay =新的ArrayList< OverlayItem>();
私人语境mContext;
私人布尔isPinch = FALSE;
公共MapOverlay(可绘制defaultMarker,上下文的背景下){
超级(boundCenterBottom((defaultMarker)));
mContext =背景;
// TODO自动生成构造函数存根
}
公共无效addOverlayItem(OverlayItem overlayItem)
{ 如果(!mOverlay.contains(overlayItem)){ mOverlay.add(overlayItem);
} 填充(); }
@覆盖
保护OverlayItem createItem中(int i)以{
// TODO自动生成方法存根
返回null;
}
@覆盖
公众诠释大小(){
// TODO自动生成方法存根
返回mOverlay.size();
}
公共布尔中的onTap(GeoPoint的P,MapView类图)
{
如果(isPinch)
{
Log.i(中的onTap,如果中!);
返回false;
}
其他
{
Log.i(中的onTap,TAP!);
如果(P!= NULL)
{
OverlayItem overlayitem =新OverlayItem(对,,); itemizedoverlay.addOverlayItem(overlayitem);
mapOverlays.add(itemizedoverlay);
Toast.makeText(getBaseContext(),
p.getLatitudeE6()/ 1E6 +,自来水+
p.getLongitudeE6()/ 1E6,
Toast.LENGTH_SHORT).show();
Log.d(变量,退出轻按);
返回true; //我们处理的自来水
}
其他
{
返回false; //空的GeoPoint
}
}
}
}
解决方案
这是我的code
希望你能得到一些想法
点P1 =新的点(0,0);
。MapView.getProjection()在toPixels(MapPoint的,P1); // MapPoint的是GeoPoint的对象
inDrag =项目; //项目从列表对象获取和inDrag是OverlayItem对象
items.remove(inDrag);项目是列表对象
填充();
GeoPoint的PT = MapView.getProjection()在fromPixels(p1.x + xDragImageOffset,p1.y)。
OverlayItem toDrop =新OverlayItem(PT,inDrag.getTitle(),inDrag.getSnippet());
items.add(toDrop);
填充();
Hello i am unable to fire ontap() event
i want to add a marker whenever i tap on map, and when i tap on another geopoint the first marker should disappear and the marker should be added on new location...
till now i have come to this point..can anybody tell me where am i going wrong!!thanks in advance
Source Code
public class GetLocation extends MapActivity implements OnClickListener {
MapView mapView;
MapController mc;
GeoPoint p;
int range;
String category;
Button view, traffic;
private static final String Tag = "GetLocation class";
ZoomControls zoomControls;
Canvas canvas;
MapOverlay itemizedoverlay;
List<Overlay> mapOverlays;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.d("Tag","Inside onCreate");
setContentView(R.layout.main);
mapView = (MapView) findViewById(R.id.myMapView1);
LinearLayout zoom = (LinearLayout)findViewById(R.id.zoom);
mapView.setReticleDrawMode(
MapView.ReticleDrawMode.DRAW_RETICLE_UNDER);
// Drawable drawable = this.getResources().getDrawable(R.drawable.mark);
view=(Button)findViewById(R.id.BtnView);
traffic=(Button)findViewById(R.id.BtnTraffic);
Bundle extra=getIntent().getExtras();
if(extra != null)
{
category=extra.getString("category");
range=extra.getInt("range");
}
view.setOnClickListener(this);
traffic.setOnClickListener(this);
zoomControls = (ZoomControls) findViewById(R.id.zoomcontrols);
zoomControls.setOnZoomInClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mc.zoomIn();
}
});
zoomControls.setOnZoomOutClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mc.zoomOut();
}
});
mapOverlays = mapView.getOverlays();
Drawable drawable = this.getResources().getDrawable(R.drawable.mark);
itemizedoverlay = new MapOverlay(drawable,this);
mc = mapView.getController();
mapView.invalidate();
mc.setZoom(17);
mapView.invalidate();
// mapView.setSatellite(true);
mapView.setStreetView(true);
// mapView.setOnClickListener(this);
Log.d("Tag","Exit onCreate");
}
class MapOverlay extends com.google.android.maps.ItemizedOverlay<OverlayItem>
{
private ArrayList<OverlayItem> mOverlay = new ArrayList<OverlayItem>();
private Context mContext;
private boolean isPinch = false;
public MapOverlay(Drawable defaultMarker,Context context) {
super(boundCenterBottom((defaultMarker)));
mContext = context;
// TODO Auto-generated constructor stub
}
public void addOverlayItem(OverlayItem overlayItem)
{
if(!mOverlay.contains(overlayItem)){
mOverlay.add(overlayItem);
}
populate();
}
@Override
protected OverlayItem createItem(int i) {
// TODO Auto-generated method stub
return null;
}
@Override
public int size() {
// TODO Auto-generated method stub
return mOverlay.size();
}
public boolean onTap(GeoPoint p, MapView map)
{
if ( isPinch )
{
Log.i("onTap","in if!");
return false;
}
else
{
Log.i("onTap","TAP!");
if ( p!=null )
{
OverlayItem overlayitem = new OverlayItem(p," ", " ");
itemizedoverlay.addOverlayItem(overlayitem);
mapOverlays.add(itemizedoverlay);
Toast.makeText(getBaseContext(),
p.getLatitudeE6() / 1E6 + ",on Tap" +
p.getLongitudeE6() /1E6 ,
Toast.LENGTH_SHORT).show();
Log.d("Tag","Exit TAp");
return true; // We handled the tap
}
else
{
return false; // Null GeoPoint
}
}
}
}
解决方案
this is my code hope you can get some idea
Point p1=new Point(0,0);
mapView.getProjection().toPixels(mapPoint, p1);// mapPoint is GeoPoint object
inDrag=item; // item get from List object and inDrag is an OverlayItem object
items.remove(inDrag); items is list object
populate();
GeoPoint pt=mapView.getProjection().fromPixels(p1.x+xDragImageOffset,p1.y);
OverlayItem toDrop=new OverlayItem(pt, inDrag.getTitle(),inDrag.getSnippet());
items.add(toDrop);
populate();
这篇关于ONTAP()在地图上的事件,不会触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!