android google map 标记,android google map添加标记和TipView
1.new一个mapoverlay并添加到map上。 mapoverlay上要绘制数据点标记和TipView:
protected void adjustCacheInMap(final List caches, CacheData selectedCache) {
// create tip view
final View mTipView = mInflater.inflate(
R.layout.mobile_mc_findcache_result_map_tipview, null);
mMapCaches.removeAllViews();
mMapCaches.addView(mTipView);
mMapCaches.post(new Runnable() {
@Override
public void run() {
mMapCaches.getOverlays().clear();
MobileResultMapOverlay mapOverlay = new MobileResultMapOverlay(
MobileFindCacheResultActivity.this, mTipView, null,
caches, mVibrator, mMapController);
mMapCaches.getOverlays().add(mapOverlay);
mMapCaches.getOverlays().add(mlo);
mMapCaches.invalidate();
}
});
}
2.MobileResultMapOverlay如下:
package com.mc.yellowbook.android.map; import java.util.ArrayList; import java.util.List; import android.app.Activity; import android.content.Intent; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Canvas; import android.graphics.Matrix; import android.graphics.Point; import android.os.Vibrator; import android.view.View; import android.widget.ImageView; import android.widget.TextView; import com.google.android.maps.GeoPoint; import com.google.android.maps.MapController; import com.google.android.maps.MapView; import com.google.android.maps.Overlay; import com.google.android.maps.Projection; import com.mc.yellowbook.android.R; import com.mc.yellowbook.android.app.AppConstants; import com.mc.yellowbook.android.app.AppUtils; import com.mc.yellowbook.android.findcache.MobileFindViewCacheActivity; import com.mc.yellowbook.android.model.BusinessData; import com.mc.yellowbook.android.model.CacheData; public class MobileResultMapOverlay extends Overlay implements android.view.View.OnClickListener { // offset for tip view private static int TIP_POSITION_X_OFFERSET = 12; private static int TIP_POSITION_Y_OFFERSET = 7; private Bitmap geoPnt = null; private CacheData selected = null; private List coll = null; private List points = null; private Activity activity; private Vibrator vibrator; private MapController mapController; private View mTipView; private TextView mTextMapTipCacheName, mTextMapTipBusinessName, mTextMapTipDistance; private ImageView mImgMapTipViewCache, mImgMapTipCacheDifficulty, mImgMapTipCacheSize; public MobileResultMapOverlay(Activity activity, View mTipView, CacheData selectedCache, List caches, Vibrator vibrator, MapController mapController) { super(); this.mapController = mapController; this.vibrator = vibrator; this.activity = activity; this.mTipView = mTipView; coll = caches; if (selectedCache == null && caches != null && caches.size() != 0) { // set the first one selected by default selected = caches.get(0); } points = new ArrayList(); final List pointsList = new ArrayList(); for (CacheData data : coll) { BusinessData p = data.getBusiness(); if (p == null) { continue; } if (p.getLatE6() == 0 && p.getLonE6() == 0) { continue; } GeoPoint pnt = new GeoPoint(p.getLatE6(), p.getLonE6()); points.add(pnt); pointsList.add(data); } if (mTipView != null) { // get View by id mTextMapTipBusinessName = (TextView) mTipView .findViewById(R.id.textResultMapTipBusinessName); mTextMapTipCacheName = (TextView) mTipView .findViewById(R.id.textResultMapTipCacheName); mTextMapTipDistance = (TextView) mTipView .findViewById(R.id.textResultMapTipDistance); mImgMapTipViewCache = (ImageView) mTipView .findViewById(R.id.imgResultMapTipViewCache); mImgMapTipCacheDifficulty = (ImageView) mTipView .findViewById(R.id.imgResultMapTipDiff); mImgMapTipCacheSize = (ImageView) mTipView .findViewById(R.id.imgResultMapTipSize); // set click listener mImgMapTipViewCache.setOnClickListener(this); } // get bitmap for point show on map geoPnt = BitmapFactory.decodeResource(activity.getResources(), R.drawable.mc_cache_flag); } @Override public boolean onTap(GeoPoint click, MapView mapView) { Projection projection = mapView.getProjection(); Point tapPoint = projection.toPixels(click, null); Point myPoint = null; int idx = 0; double min_dis = Math.pow(25.0, 2); CacheData cache = null; for (CacheData data : coll) { BusinessData p = data.getBusiness(); if (p == null || (p.getLatE6() == 0 && p.getLonE6() == 0)) { continue; } myPoint = projection.toPixels(points.get(idx), null); double dis = Math.pow(tapPoint.x - myPoint.x, 2.0) + Math.pow(tapPoint.y - myPoint.y, 2.0); if (dis < min_dis) { min_dis = dis; cache = data; } idx++; } // if (cache != null) { if (cache != selected) { selected = cache; // mTipView.setVisibility(View.VISIBLE); } // } if (selected != null) { // move selected cache to map center BusinessData selectedBusiness = selected.getBusiness(); mapController.animateTo(new GeoPoint(selectedBusiness.getLatE6(), selectedBusiness.getLonE6())); } return false; } @Override public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) { Projection projection = mapView.getProjection(); Matrix matrix = new Matrix(); float scale = 0.7f; matrix.postScale(scale, scale); int width = geoPnt.getWidth(); int height = geoPnt.getHeight(); Bitmap newGeoPnt = null; newGeoPnt = Bitmap.createBitmap(geoPnt, 0, 0, width, height, matrix, true); width = newGeoPnt.getWidth(); height = newGeoPnt.getHeight(); // draw all points int idx = 0; for (CacheData data : coll) { BusinessData p = data.getBusiness(); if (p == null || (p.getLatE6() == 0 && p.getLonE6() == 0)) { continue; } Point point = new Point(); projection.toPixels(points.get(idx), point); canvas.drawBitmap(newGeoPnt, point.x - width, point.y - height, null); idx++; } // show tip information if (selected != null) { Point point = new Point(); projection.toPixels(new GeoPoint(selected.getBusiness().getLatE6(), selected.getBusiness().getLonE6()), point); // show the information in the tip. MapView.LayoutParams pos = (MapView.LayoutParams) mTipView .getLayoutParams(); GeoPoint geop = new GeoPoint(selected.getBusiness().getLatE6(), selected.getBusiness().getLonE6()); pos.point = geop; pos.x = -width / 2 + TIP_POSITION_X_OFFERSET; pos.y = -height - mTipView.getHeight() / 2 + TIP_POSITION_Y_OFFERSET; mTipView.setLayoutParams(pos); // set the text mTextMapTipBusinessName.setText(selected.getBusiness().getName()); mTextMapTipCacheName.setText(selected.getTitle()); mTextMapTipDistance.setText(selected.getBusiness().getOneDecimalDistance()); mImgMapTipCacheDifficulty.setImageLevel(selected.getDifficulty()); mImgMapTipCacheSize.setImageLevel(selected.getSize()); mTipView.setVisibility(View.VISIBLE); mTipView.bringToFront(); } else { mTipView.setVisibility(View.GONE); } return super.draw(canvas, mapView, shadow, when); } @Override public void onClick(View v) { AppUtils.vibrate(vibrator); if(v == mImgMapTipViewCache){ // go to view cache page Intent i = new Intent(activity, MobileFindViewCacheActivity.class); i.putExtra(AppConstants.INTENT_EXTRA_CACHE_DETAIL, selected); activity.startActivity(i); } } }
android google map 标记,android google map添加标记和TipView相关推荐
- android google map 标记,android,在googlemap上从位图添加标记
我正在使用googlemap-android-api v2,并希望在运行时从位图创建标记.所以,我做的:android,在googlemap上从位图添加标记 BitmapFactory.Options ...
- php怎么实现在图片上做标记,如何给图片添加标记(notes)?
最近几天没有更新文章,有点小忙!呵呵,不说废话,直接进入正题. 今天主要说的是,如何在图片上添加标记(一个或多个).从网上搜到很多的例子,总体来说,感觉这个很不错!! 我就简单说一下这个标记是怎么存储 ...
- Google Map API v2 (三)----- 地图上添加标记(Marker),标记info窗口,即指定经纬度获取地址字符串...
接上篇 http://www.cnblogs.com/inkheart0124/p/3536322.html 1,在地图上打个标记 1 private MarkerOptions mMarkOptio ...
- 开发基于 Google Map 的 Android 应用
开发基于 Google Map 的 Android 应用 张 谦, 软件工程师, IBM 吴 校军, 高级软件工程师, IBM 苏 琳, 软件工程师, IBM 简介: 随着移动互联网应用的迅速发展,利 ...
- google map for Android
因为政策原因,google map在国内鲜有人使用,但是如果涉及到国外的项目,又不得不和google map接触,借着自己做的项目,在这里简单介绍一下google map for Android的使用 ...
- android google map key,android google map api key取得?
我有一个项目的谷歌地图apikey现在我想要另一个项目的apikey和这个项目的keystore是在一个不同的地方.我的第一个cmd:android google map api key取得? &qu ...
- android手机安装时缺少google map api 的解决方法
有些android手机,机器里没有com.google.android.maps.jar这个包. 所以当开发使用了google map api的程序时,即使在模拟器上没有问题,但是在真机上无法安装 ...
- Android好书推荐:《Google Android SDK开发范例》
http://www.jizhuomi.com/android/book/51.html <Google Android SDK开发范例大全(第3版)>采用范例集的形式,由浅入深地带领Go ...
- swagger map示例_Android Google Map Street View示例
swagger map示例 In this tutorial, we'll be implementing the StreetView feature of Google Maps in our A ...
最新文章
- Android(java)学习笔记96:layout_weight使用注意事项
- R语言构建文本分类模型并使用LIME进行模型解释实战:文本数据预处理、构建词袋模型、构建xgboost文本分类模型、基于文本训练数据以及模型构建LIME解释器解释多个测试语料的预测结果并可视化
- 获得H.264视频分辨率的方法
- 黄聪:Python+NLTK自然语言处理学习(三):计算机自动学习机制
- 学习lulu之——tips 提示
- Web应用开发技术(2)-html
- Qt第三方库QCustomPlot——认识图表的各个部分
- 优秀程序员的45个习惯
- shell 获取家目录_一篇教会你写90%的shell脚本
- priority_queue用法
- 倾力打造在线SAP学习练习测试系统,能上网就可以使用SAP
- Photoshop插件-黑白(四)-脚本开发-PS插件
- LINUX摄像头驱动分析
- 键盘测试软件 - Vintage Keyboard Analyzer
- app开发者帐号(个人开发帐号、团队帐号、企业帐号、教育帐号)
- matlab圆锥曲线,圆锥曲线:MATLAB绘制椭圆方程的图像 来充电吧
- AForge.NET Framework2.25--图像视觉处理学习(五)---颜色转换
- uiautomator2+ tesseract 智能识别文字实现手游辅助外挂,打怪刷装备快人一步
- video视频标签怎么禁止用户拖动进度条快进
- Developpeur Reference对Bjarne Stroustrup的采访(转载)