当前位置:三九宝宝网 → 宝宝教育 → 智力培养 → 正文

android开发地图怎么实现自定义弹出窗口

更新:02-25 整理:39baobao.com
字体:

[JSP自定义标签开发流程]jsp(SUN企业级应用的首选)中有一块重要的技术:自定义标签(Custom Tag),最近这几天在学习Struts的时候发现Struts中使用了很多自定义标签,如html、bean等。所以我就做了个简单的试验...+阅读

基本原理就是用ItemizedOverlay来添加附加物,在OnTap方法中向MapView上添加一个自定义的View(如果已存在就直接设为可见),下面具体来介绍我的实现方法:一、自定义覆盖物类:MyPopupOverlay,这个类是最关键的一个类ItemizedOverlay,用于设置Marker,并定义Marker的点击事件,弹出窗口,至于弹出窗口的内容,则通过定义Listener,放到Activity中去构造。如果没有特殊需求,这个类不需要做什么改动。代码如下,popupLinear这个对象,就是加到地图上的自定义View: public class MyPopupOverlay extends ItemizedOverlay{ private Context context = null; // 这是弹出窗口, 包括内容部分还有下面那个小三角 private LinearLayout popupLinear = null; // 这是弹出窗口的内容部分 private View popupView = null; private MapView mapView = null; private Projection projection = null; // 这是弹出窗口内容部分使用的layoutId,在Activity中设置 private int layoutId = 0; // 是否使用带有A-J字样的Marker private boolean useDefaultMarker = false; private int[] defaultMarkerIds = { R.drawable.icon_marka, R.drawable.icon_markb, R.drawable.icon_markc, R.drawable.icon_markd, R.drawable.icon_marke, R.drawable.icon_markf, R.drawable.icon_markg, R.drawable.icon_markh, R.drawable.icon_marki, R.drawable.icon_markj, }; // 这个Listener用于在Marker被点击时让Activity填充PopupView的内容 private OnTapListener onTapListener = null; public MyPopupOverlay(Context context, Drawable marker, MapView mMapView) { super(marker, mMapView); this.context = context; this.popupLinear = new LinearLayout(context); this.mapView = mMapView; popupLinear.setOrientation(LinearLayout.VERTICAL); popupLinear.setVisibility(View.GONE); projection = mapView.getProjection(); } Override public boolean onTap(GeoPoint pt, MapView mMapView) { // 点击窗口以外的区域时,当前窗口关闭 if (popupLinear != null & popupLinear.getVisibility() == View.VISIBLE) { LayoutParams lp = (LayoutParams) popupLinear.getLayoutParams(); Point tapP = new Point(); projection.toPixels(pt, tapP); Point popP = new Point(); projection.toPixels(lp.point, popP); int xMin = popP.x - lp.width / 2 + lp.x; int yMin = popP.y - lp.height + lp.y; int xMax = popP.x + lp.width / 2 + lp.x; int yMax = popP.y + lp.y; if (tapP.xxMax || tapP.y >yMax) popupLinear.setVisibility(View.GONE); } return false; } Override protected boolean onTap(int i) { // 点击Marker时,该Marker滑动到地图中央偏下的位置,并显示Popup窗口 OverlayItem item = getItem(i); if (popupView == null) { // 如果popupView还没有创建,则构造popupLinear if (!createPopupView()){ return true; } } if (onTapListener == null) return true; popupLinear.setVisibility(View.VISIBLE); onTapListener.onTap(i, popupView); popupLinear.measure(0, 0); int viewWidth = popupLinear.getMeasuredWidth(); int viewHeight = popupLinear.getMeasuredHeight(); LayoutParams layoutParams = new LayoutParams(viewWidth, viewHeight, item.getPoint(), 0, -60, LayoutParams.BOTTOM_CENTER); layoutParams.mode = LayoutParams.MODE_MAP; popupLinear.setLayoutParams(layoutParams); Point p = new Point(); projection.toPixels(item.getPoint(), p); p.y = p.y - viewHeight / 2; GeoPoint point = projection.fromPixels(p.x, p.y); mapView.getController().animateTo(point); return true; } private boolean createPopupView() { // TODO Auto-generated method stub if (layoutId == 0) return false; popupView = LayoutInflater.from(context).inflate(layoutId, null); popupView.setBackgroundResource(R.drawable.popupborder); ImageView dialogStyle = new ImageView(context); dialogStyle.setImageDrawable(context.getResources().getDrawable( R.drawable.iw_tail)); popupLinear.addView(popupView); android.widget.LinearLayout.LayoutParams lp = new android.widget.LinearLayout.LayoutParams( LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); lp.topMargin = -2; lp.leftMargin = 60; popupLinear.addView(dialogStyle, lp); mapView.addView(popupLinear); return true; } Override public void addItem(Listitems) { // TODO Auto-generated method stub int startIndex = getAllItem().size(); for (OverlayItem item : items){ if (startIndex >= defaultMarkerIds.length) startIndex = defaultMarkerIds.length - 1; if (useDefaultMarker & item.getMarker() == null){ item.setMarker(context.getResources().getDrawable( defaultMarkerIds[startIndex++])); } } super.addItem(items); } Override public void addItem(OverlayItem item) { // TODO Auto-generated method stub // 重载这两个addItem方法,主要用于设置自己默认的Marker int index = getAllItem().size(); if (index >= defaultMarkerIds.length)...

急求android地图开发怎样设置地图中心

android地图怎样获得地图中心点的经纬坐标GeoPoint point =new GeoPoint((int)(jd*1e6), (int)(wd*1e6));我想获得当前地图中心的经纬赋值给point地图中心是可以变的,比如我拖动地图中心就变,用甚么代码表示中心点?找了api没找到请提供代码,初学,没代码不懂------解决方案--------------------地图中心点1开始是你set进去的,你移动过后可以根据你移动的像素PIXEL再转换到LATLNG,加上偏移量就是你移动过后的新的中心点了。 ------解决方案--------------------这个需要将屏幕坐标转换成地图坐标。具体步骤是:获得到当前屏幕的中心点,然后将这个中心点转换到当前地图显示的中心点不可以获得到了 。

本文地址:https://www.39baobao.com/show/32_80986.html

以上内容来自互联网,请自行判断内容的正确性。若本站收录的信息无意侵犯了贵司版权,请联系我们,我们会及时处理和回复,谢谢.

以下为关联文档:

如何开发自定义表单简单的开发通过自定义表单就可以实现,在线开发,不用编译就可使用功能。 自定义表单开发工具介绍 做自定义表单首先需要在数据库中建立好存储表单数据的数据表。 建表有以下两...

android平台地图如何实现如图所示功能给你看一点地图开发的教程吧:8208168这里的博客里有八篇讲解怎么使用地图的,个人觉得还是很详细到位的。 至于你的需求,可以这样实现: 首先,你要获取到自己的数据列表,包括店名、...

android开发百度地图哪个API可以设置地图是否可以拖动android地图怎样获得地图中心点的经纬坐标GeoPoint point =new GeoPoint((int)(jd*1e6), (int)(wd*1e6));我想获得当前地图中心的经纬赋值给point地图中心是可以变的,比如我拖...

急求android百度地图开发怎样设置地图中心android地图怎样获得地图中心点的经纬坐标GeoPoint point =new GeoPoint((int)(jd*1e6), (int)(wd*1e6));我想获得当前地图中心的经纬赋值给point地图中心是可以变的,比如我拖...

Android开发简单拨号器实现public class MainActivity extends ActionBarActivity { Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setConte...

高德地图 android开发中怎么用经纬度来显示地图首先创建工程,并在工程Build Path>Configure Build Path…>libraries 中选择“Add Externel JARs…”,选定 MapApi.jar,点击OK,这样就可以将高德地图Android API 库文件引入。然...

android自定义软键盘键盘怎么自定义改键定义键盘整个过程如下: 1.第一步,根据你的需求,需要定制怎样的键盘,需要几行几列,准备好键盘按键的背景图片,键盘的尺寸,在res文件下,新建一个xml文件,下面放字母、数字、标点符号...

Android开发中怎么使用自定义字体1、Android系统默认支持三种字体,,分别为:“sans”, “serif”, “monospace2、在Android中可以引入其他字体 。 Android:layout_width="fill_parent" Android:layout_height="fil...

Android调用照相机和地图开发地图显示界面覆盖了相机android手机有自带的照相机和图库,我们做的项目中有时用到上传图片到服务器,今天做了一个项目用到这个功能,所以把我的代码记录下来和大家分享,有需求的朋友可以参考下android手...