htc 的地图上不显示标记
我被困住了,我尝试了一切可能性,但没有成功。我已经创建了带有地图的简单应用程序以进行测试,用户可以简单地触摸地图并在该位置放置标记。这将在除 htc 设备之外的所有设备上成功运行。我不知道如何为mapview实现onTouch事件
这是我的onTouch代码
private class MarkerOverlay extends Overlay{
private boolean isMove;
@Override
public boolean onTouchEvent(MotionEvent e, MapView mapView) {
final int x = (int) e.getX();
final int y = (int) e.getY();
if(e.getAction()==1){
if(!isMove){
geopoint = mapView.getProjection().fromPixels(x, y);
OverlayItem overlayItem = new OverlayItem(geopoint, "Title", "Description");
if(mapOverlay.m_overlays.size()>=1){
mapOverlay.clearOverlayAll();
}
mapOverlay.addOverlay(overlayItem);
if(!mapView.getOverlays().contains(mapOverlay))
mapView.getOverlays().add(mapOverlay);
mapView.invalidate();
Toast.makeText(SimpleMapMarkerActivity.this, "in press", Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(SimpleMapMarkerActivity.this, "out press", Toast.LENGTH_SHORT).show();
}
}else if(e.getAction()==MotionEvent.ACTION_DOWN)
isMove = false;
else if(e.getAction()==MotionEvent.ACTION_MOVE)
isMove = true;
return super.onTouchEvent(e, mapView);
}
}
I am stuck with this, I have tried every possibility but not success. I have create simple application with map for testing and user can simple touch on map and on that place put the marker. This will work successfully in all device except in htc devices. I don't know how to implement onTouch event for mapview
here is my code for onTouch
private class MarkerOverlay extends Overlay{
private boolean isMove;
@Override
public boolean onTouchEvent(MotionEvent e, MapView mapView) {
final int x = (int) e.getX();
final int y = (int) e.getY();
if(e.getAction()==1){
if(!isMove){
geopoint = mapView.getProjection().fromPixels(x, y);
OverlayItem overlayItem = new OverlayItem(geopoint, "Title", "Description");
if(mapOverlay.m_overlays.size()>=1){
mapOverlay.clearOverlayAll();
}
mapOverlay.addOverlay(overlayItem);
if(!mapView.getOverlays().contains(mapOverlay))
mapView.getOverlays().add(mapOverlay);
mapView.invalidate();
Toast.makeText(SimpleMapMarkerActivity.this, "in press", Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(SimpleMapMarkerActivity.this, "out press", Toast.LENGTH_SHORT).show();
}
}else if(e.getAction()==MotionEvent.ACTION_DOWN)
isMove = false;
else if(e.getAction()==MotionEvent.ACTION_MOVE)
isMove = true;
return super.onTouchEvent(e, mapView);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我得到了解决方案以及harism给出的解决方案
每当您只需使用地图实现标记时,就像点击地图并显示市场一样,然后实现
onTap(GeoPoint g, MapView mapview)
。如果您想实现像拖放一样由用户移动的标记,则可以使用
onTouch()
来实现。对于onTouch()
和拖放等移动标记,请检查此链接http://www.edumobile.org/android/android-apps/mapmarkerexample/
I got the solution and this solution given by harism
Whenever you just implement the marker with map as just like tap on map and display the market then implement the
onTap(GeoPoint g, MapView mapview)
.And if you want to implement the marker like moving by user like drag and drop then implement by using
onTouch()
. ForonTouch()
and moving marker like drag and drop check this linkhttp://www.edumobile.org/android/android-apps/mapmarkerexample/
我也有同样的问题。我不确定它是否可以解决你的 htc 问题。但这就是我所做的:
我重写了dispatchTouchEvent。它适用于我的三星 Galaxy s2。
我在mapActivity 中这样做了。不在覆盖中。
I had the same problem. I am not sure if it can solve you htc problem. But here's what I did:
I've overridden the dispatchTouchEvent. It works on my Samsung Galaxy s2.
I am doint this in mapActivity. not in overLay.
MapMarkerExample
此示例向您展示如何在地图上绘制可移动标记。您可以拖放标记来更改其位置。可用于任何您想要从用户那里获取地图位置输入的应用程序。
算法:
1.) 通过File->创建一个新项目新-> Android 项目将其命名为 MapMarkerExample。
2.) 您将在 main.xml 和 android 清单文件中看到一些默认代码。
3.) 将互联网权限添加到清单文件或在 android.manifest 文件中写入以下内容:
http ://www.edumobile.org/android/android-apps/mapmarkerexample/
MapMarkerExample
This example show you how to draw movable marker on to map. You can darg and drop the marker to change its position. Can be used in any application where u want to take input from user for map location.
Algorithm:
1.) Create a new project by File-> New -> Android Project name it MapMarkerExample.
2.) You will see some default code into your main.xml and android manifest file.
3.) Add internet permission to your manifest file or write following in android.manifest file:
http://www.edumobile.org/android/android-apps/mapmarkerexample/