android版百度地图 自定义 点击当前位置弹出气泡

本文详细介绍了如何在地图应用中继承并重写 MyLocationOverlay 类,实现点击位置时弹出自定义信息框的功能。通过创建一个自定义布局文件和相应的 view 获取函数,实现了点击位置时显示包含城市和地址信息的弹窗。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

[java]  view plain copy
  1.     //继承MyLocationOverlay重写dispatchTap实现点击处理  
  2.     public class locationOverlay extends MyLocationOverlay{  
  3.   
  4.         public locationOverlay(MapView mapView) {  
  5.             super(mapView);  
  6.             // TODO Auto-generated constructor stub  
  7.         }  
  8.         @Override  
  9.         protected boolean dispatchTap() {  
  10.             // TODO Auto-generated method stub  
  11. //              //处理点击事件,弹出泡泡  
  12. //              popupText.setBackgroundResource(R.drawable.popup);  
  13. //          popupText.setText("我的位置");  
  14.             /** 
  15.              * 把一个xml布局文件转化成view 
  16.              */  
  17. //              public View getView(String title, String text) {  
  18.                 View view = getLayoutInflater().inflate(R.layout.marker, null);  
  19.                 TextView text_title = (TextView) view.findViewById(R.id.marker_title);  
  20.                 TextView text_text = (TextView) view.findViewById(R.id.marker_text);  
  21.                 SpannableString titleText = new SpannableString(temLocation.getCity());  
  22.                 titleText.setSpan(new ForegroundColorSpan(Color.RED), 0,  
  23.                         titleText.length(), 0);  
  24.                 text_title.setText(titleText);  
  25.                 SpannableString texttext = new SpannableString(temLocation.getAddrStr());  
  26.                 texttext.setSpan(new ForegroundColorSpan(Color.BLACK), 0,  
  27.                         texttext.length(), 0);  
  28.                 text_text.setText(texttext);  
  29. //                  return view;  
  30. //              }  
  31. //          pop.showPopup(BMapUtil.getBitmapFromView(popupText),  
  32.                 pop.showPopup(BMapUtil.getBitmapFromView(view),  
  33.                     new GeoPoint((int)(locData.latitude*1e6), (int)(locData.longitude*1e6)),  
  34.                     8);  
  35.             return true;  
  36.         }  
  37.           
  38.     }  
[html]  view plain copy
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:layout_width="match_parent"  
  4.     android:layout_height="match_parent"  
  5.     android:background="@drawable/custom_info_bubble"  
  6.     android:orientation="vertical" >  
  7.   
  8.     <TextView  
  9.         android:id="@+id/marker_title"  
  10.         android:layout_width="wrap_content"  
  11.         android:layout_height="wrap_content" />  
  12.   
  13.     <TextView  
  14.         android:id="@+id/marker_text"  
  15.         android:layout_width="wrap_content"  
  16.         android:layout_height="wrap_content" />  
  17.   
  18. </LinearLayout>  


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值