百度地图之标注物聚合----在聚合物的中心点显示本地照片
2014-07-21 13:05
267 查看
参考资料:
http://blog.csdn.net/fengshuiyue/article/details/9328293
http://www.eoeandroid.com/thread-322074-1-1.html
这两个都是实现了百度地图标注物聚合的功能,用到的基本思想基本上一致的。代码可以下载下来直接使用。
在它们的基础上,我将图中的点换成了照片本地的照片,而且数据库中照片存储的信息不仅包括照片的名称还包括照片拍摄的地理位置(包括经纬度和地区),随着缩放比例的变化,聚合物的数量在变化,聚合物的内容也在发生,照片的数量与内容也在发生变化。
Cluster类是聚合器,ClusterMarker是聚合标注物的功能。在编码过程中遇到的问题是如何来判断一个点处于聚合物中以及如何根据聚合物找到聚合物中的点,根据点找到对应的照片,并将第一张照片显示在地图上,以便在点击地图上显示的照片时,可以只查看该聚合物内坐标点处拍的照片。
---------------程序的入口类 ---------------
用以上方法就可以获得某个标注物中照片名称的集合。
---------------Cluster类中的createCluster(List<OverlayItem> markerList)函数和setClusterDrawable(ClusterMarker clusterMarker)函数修改 ---------------
注明:
DBManger类:对SQLite数据库操作的类。
queryByFirstPhoto(double longitude,double latitude)函数为根据经纬度查询第一张照片的名称。
ImageSpan imgSpan = new ImageSpan(getFirstImage(image_path));
SpannableString spanString = new SpannableString("icon");
spanString.setSpan(imgSpan, 0, 4, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
text.setText(spanString);
以上四行代码可以实现在textview中显示图片。
这个函数可以实现根据路径获得照片。
根据自己的项目修改小细节的部分就不说啦。
http://blog.csdn.net/fengshuiyue/article/details/9328293
http://www.eoeandroid.com/thread-322074-1-1.html
这两个都是实现了百度地图标注物聚合的功能,用到的基本思想基本上一致的。代码可以下载下来直接使用。
在它们的基础上,我将图中的点换成了照片本地的照片,而且数据库中照片存储的信息不仅包括照片的名称还包括照片拍摄的地理位置(包括经纬度和地区),随着缩放比例的变化,聚合物的数量在变化,聚合物的内容也在发生,照片的数量与内容也在发生变化。
Cluster类是聚合器,ClusterMarker是聚合标注物的功能。在编码过程中遇到的问题是如何来判断一个点处于聚合物中以及如何根据聚合物找到聚合物中的点,根据点找到对应的照片,并将第一张照片显示在地图上,以便在点击地图上显示的照片时,可以只查看该聚合物内坐标点处拍的照片。
---------------程序的入口类 ---------------
List<OverlayItem> clusters=mCluster.createCluster(mMarkers); itemOverlay.removeAll(); for(int i=0;i<clusters.size();i++){//以聚合物的总数量作为最外层循环 int z=0,num_photo=0; Cursor cursorFirstPhoto; String location="",first_photo=""; GeoPoint markGeo=clusters.get(i).getPoint();//聚合物的中心点 ArrayList <GeoPoint> geoP=new ArrayList<GeoPoint>(); Bounds bound = new Bounds(markGeo.getLatitudeE6(),markGeo.getLongitudeE6(),markGeo.getLatitudeE6(),markGeo.getLongitudeE6()); bound=MapUtils.getExtendedBounds(mMapView, bound, mGridSize); for(int j=0;j<mMarkers.size();j++){//以点的总个数作为内层循环 if(mCluster.isMarkersInCluster(mMarkers.get(j).getPoint(),bound)){//判断一个点是否处于该聚合物中 geoP.add(mMarkers.get(j).getPoint()); ArrayList<String>name=new ArrayList<String>(); double longitude=(mMarkers.get(j).getPoint().getLongitudeE6())/10E5; double latitude=(mMarkers.get(j).getPoint().getLatitudeE6())/10E5; Cursor cursor=dbM.queryByLocation(longitude, latitude); cursor.moveToFirst(); String photos=cursor.getString(cursor.getColumnIndex("photo_id")); cursorFirstPhoto=dbM.query(photos); String lo=cursorFirstPhoto.getString(cursorFirstPhoto.getColumnIndex("location")); for(cursor.moveToFirst();!(cursor.isAfterLast());cursor.moveToNext()){ String photo_name=cursor.getString(cursor.getColumnIndex("photo_id")); name.add(photo_name); num_photo++; } z++; } } }
用以上方法就可以获得某个标注物中照片名称的集合。
---------------Cluster类中的createCluster(List<OverlayItem> markerList)函数和setClusterDrawable(ClusterMarker clusterMarker)函数修改 ---------------
public ArrayList<OverlayItem> createCluster(List<OverlayItem> markerList){ this.mClusterMarkers.clear(); ArrayList<OverlayItem> itemList = new ArrayList<OverlayItem>(); for(int i=0;i<markerList.size();i++){ addCluster(markerList.get(i)); } for(int i=0;i<mClusterMarkers.size();i++){ ClusterMarker cm=mClusterMarkers.get(i); double longitude=cm.getPoint().getLongitudeE6()/10E5; double latitude=cm.getPoint().getLatitudeE6()/10E5; DBManager dbM=new DBManager(); Cursor cursor=dbM.queryByFirstPhoto(longitude, latitude); cursor.moveToFirst(); String first_photo=cursor.getString(cursor.getColumnIndex("photo_id")); setClusterDrawable(cm,first_photo); OverlayItem oi = new OverlayItem(cm.getmCenter(),cm.getTitle(),cm.getSnippet()); oi.setMarker(cm.getMarker()); itemList.add(oi); } return itemList; }
注明:
DBManger类:对SQLite数据库操作的类。
queryByFirstPhoto(double longitude,double latitude)函数为根据经纬度查询第一张照片的名称。
private void setClusterDrawable(ClusterMarker clusterMarker,String image){ View drawableView=LayoutInflater.from(context).inflate(R.layout.drawable_mark,null); TextView text=(TextView)drawableView.findViewById(R.id.drawble_mark); DBManager dbM=new DBManager(); Cursor cursorFirstPhoto=dbM.query(image); String lo=cursorFirstPhoto.getString(cursorFirstPhoto.getColumnIndex("location")); System.out.println("2020002020202"+lo); String image_path=Environment.getExternalStorageDirectory().getPath()+ "/"+"traveljournal/"+lo+"/"+image; ImageSpan imgSpan = new ImageSpan(getFirstImage(image_path)); SpannableString spanString = new SpannableString("icon"); spanString.setSpan(imgSpan, 0, 4, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); text.setText(spanString); Bitmap bitmap = MapUtils.convertViewToBitmap(drawableView); clusterMarker.setMarker(new BitmapDrawable(bitmap)); }
ImageSpan imgSpan = new ImageSpan(getFirstImage(image_path));
SpannableString spanString = new SpannableString("icon");
spanString.setSpan(imgSpan, 0, 4, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
text.setText(spanString);
以上四行代码可以实现在textview中显示图片。
public Bitmap getFirstImage(String path){ Bitmap b=null; try { InputStream is = new FileInputStream(path); BitmapFactory.Options options = new BitmapFactory.Options(); options.inPreferredConfig = Config.ARGB_8888; options.inJustDecodeBounds = false; options.inSampleSize = 2; b = BitmapFactory.decodeStream(is, null, options); int width = b.getWidth(); int height = b.getHeight(); // 根据自己的需要设置照片的大小 int newWidth = 200; int newHeight = 200; // 计算缩放比例 float scaleWidth = ((float) newWidth) / width; float scaleHeight = ((float) newHeight) / height; // 取得想要缩放的matrix参数 Matrix matrix = new Matrix(); matrix.postScale(scaleWidth, scaleHeight); // 得到新的图片 b = Bitmap.createBitmap(b, 0, 0, width, height, matrix, true); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } return b; }
这个函数可以实现根据路径获得照片。
根据自己的项目修改小细节的部分就不说啦。
相关文章推荐
- 设置 百度地图 的显示的地图中心 和缩放级别
- WPF Image显示本地照片 判断选择删除
- android获取并显示camera拍摄或者本地图库的照片
- 百度地图 地图拖动结束时显示地图中心
- 百度地图嵌入弹出层,无法准确正确显示marker标记到中心位置的问题
- 安卓图片操作(调用系统相机,预览本地照片,调用系统裁剪图片,压缩图片,中心裁剪方形图片,bitmap转byte[])
- 百度地图开发 随着鼠标移动在状态栏显示鼠标中心的坐标
- AssetsLibrary显示本地照片
- Fragment获取本地照片显示之Activity 的ontActivityResult()
- 2017战略No.4:不做亏本的买卖-搭建本地WordPress网站,人工聚合“以经济建设为中心”的优质内容
- Android拍照 图库照片本地显示
- 百度地图之标注物聚合
- MapView 百度地图 (锁定到以当前经纬度为中心点的显示区域和合适的显示范围 )
- Android 使用系统相机拍摄照片保存到本地并在系统相册中显示
- 关于百度地图(四):点聚合及只显示屏幕范围内的marker
- 安卓开启照相机并保存本地显示高清照片
- 在h5中用JS从本地引入照片及其显示
- 浏览器显示本地照片 image
- Android保存照片到本地,并立即更新在相册显示
- 百度地图经纬度转换+反地址解析+显示可视区域内标注点+地图自动刷新+标注的聚合