android+-+MapView地图里标记自己的地点,生成新的地点
来源:互联网 发布:php substr函数的用法 编辑:程序博客网 时间:2024/05/23 01:26
/** * This is class for touch event ,when user touched the screen for * enough time, user can tag the touched place as user's favorite * place, or fix current position and set as destination. * @author xinyan *@date 2011-10-10 */class Touchy extends Overlay {@Overridepublic boolean onTouchEvent(MotionEvent e, MapView mapView) {Log.v(TAG, "Touchy is touched...");if (MotionEvent.ACTION_DOWN == e.getAction()) {start = e.getEventTime();x = (int) e.getX();y = (int) e.getY();touchPoint = mMapView.getProjection().fromPixels(x, y);Log.v(TAG, "Touchy is touched.. and we get touch point.");}if (MotionEvent.ACTION_UP == e.getAction()) {stop = e.getEventTime();}if (stop - start > 1500) {OverlayItem overlayItem = new OverlayItem(touchPoint,"Pined position", "A new position");CustomPinpoint custom = new CustomPinpoint(marker,StandardActivity.this);custom.insertPinpoint(overlayItem);mMapView.getOverlays().add(custom);new AlertDialog.Builder(StandardActivity.this).setIcon(null).setTitle(R.string.whatYouWant).setSingleChoiceItems(R.array.select_dialog_whatYouWant, 0,new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialog,int whichButton) {if (0 == whichButton) {// user clicked fix my current// position choice} else if (1 == whichButton) {// user clicked set as destination// choice}}}).setPositiveButton(R.string.positive,new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialog,int whichButton) {if (0 == whichButton) {// user clicked fix my current// position choice} else if (1 == whichButton) {// user clicked set as destination// choice} else if (3 == whichButton) {// user clicked put into favorite// choice}}}).setNegativeButton(R.string.cancel,new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialog,int whichButton) {dialog.dismiss();}}).create().show();} // end of if (stop - start > 1500)else {// I think this overrided method shouldn't capture all// of the touch events, otherwise we can't control the map.return false;}return true;}}
/** * This is a custom class of pin point overlay, * it means this overlay appears a marker when you click a place on * the mapview. The StandardActivtiy will use it. * @author xinyan *@date 2011-10-9 * */public class CustomPinpoint extends ItemizedOverlay<OverlayItem> {private final ArrayList<OverlayItem> pinpoints = new ArrayList<OverlayItem>();private Context c;public CustomPinpoint(Drawable defaultMarker) {super(defaultMarker);// TODO Auto-generated constructor stub}public CustomPinpoint(Drawable marker, Context context) {this(marker);c = context;}@Overrideprotected OverlayItem createItem(int i) {return pinpoints.get(i);}@Overridepublic int size() {return pinpoints.size();}public void insertPinpoint(OverlayItem item) {pinpoints.add(item);this.populate();}}
说明下这里所说的标记地点是当你长按地图某个地方的时候,就生成一个新的气泡标记它。
关键的地方就是Touchy这个Overlay子类,它实现了Touch事件的响应方法。我们只要在onCreate方法里面把Touchy的对象,也就是实现了Touch事件的响应方法的Overlay这一层加进MapView里的Overlays里面去,就可以实现事件的响应了、、当事件响应后我们就可以标记气泡,然后取得地址、想干嘛、干嘛
貌似还有更简单的方法、、那就是CustomPinpoint覆盖ItemizedOverlay里面的public boolean onTap(GeoPoint p, MapView mapView) 、、、没试过、、如果是这样就可以不用Touchy这个类了
- android+-+MapView地图里标记自己的地点,生成新的地点
- 地图的定位,搜索,地点标记
- android学习之基于百度地图的地点检索和标记
- 创建新的库存地点
- 百度地图-显示特定的地点
- 地点的副词
- VPS的一些地点
- 高德地图1---地图加载、标记地点、信息窗体
- 地点
- 地点
- Android:使用百度地图SDK定位当前具体位置(类似QQ发表说说的选择地点功能)
- Android实现两个地点距离的查询(使用高德地图)
- Android高德地图使用之地点关键词的输入提示-InputTips
- swift 中高德地图随时读取坐标地点的写法
- 一个借用地点获得经纬度的百度地图程序
- 高德地图api的自定义地点标注
- MFC中自己定义的各个函数代码地点
- 本人的其它活跃地点
- Web 应用
- Web 应用
- Adobe Flash Builder 4 注册码
- Shader 点光源和自阴影
- Post-Screen Shaders和Rocket Commander游戏
- android+-+MapView地图里标记自己的地点,生成新的地点
- 聚光灯+法线贴图 shader
- 实时渲染的水特效
- 第六课学习二
- 对于法线贴图(Normal Map) 的深入研究
- tcpdump
- ARM芯片选型的一些建议
- OpenGL在VS2008下环境配置
- 【总结】关于tomcat+6.0中使用连接池的问题