阿里巴巴怎样做网站,app外包推广,怎么建立一个网站网址,wordpress编辑器 模板前言#xff1a;在android开发过程中#xff0c;百度地图的使用是比较普遍的#xff0c;但是如何使用#xff0c;使用什么版本的百度API还是需要一些讲究。在项目过程中#xff0c;需要用到百度地图的marker和InfoWindow的功能。标注覆盖物(百度地图官方图)布局文件很简单…前言在android开发过程中百度地图的使用是比较普遍的但是如何使用使用什么版本的百度API还是需要一些讲究。在项目过程中需要用到百度地图的marker和InfoWindow的功能。标注覆盖物(百度地图官方图)布局文件很简单主要就是mapview,如下android:layout_widthmatch_parent android:layout_heightmatch_parentandroid:orientationverticalandroid:backgroundcolor/overall_bgandroid:layout_widthmatch_parentandroid:layout_heightwrap_contentandroid:orientationhorizontalandroid:idid/gps_button_resetandroid:layout_width0dpandroid:layout_heightwrap_contentandroid:layout_weight1android:textstring/gps_reset_buttonandroid:layout_marginBottom8dpandroid:layout_marginLeft16dpandroid:layout_marginTop8dpandroid:layout_marginRight16dp/android:idid/gps_button_historyandroid:layout_width0dpandroid:layout_heightwrap_contentandroid:layout_weight1android:textstring/gps_history_buttonandroid:layout_marginBottom8dpandroid:layout_marginLeft16dpandroid:layout_marginTop8dpandroid:layout_marginRight16dp/android:layout_widthmatch_parentandroid:layout_heightwrap_contentandroid:textstring/gps_textandroid:paddingBottom8dpandroid:paddingTop8dpandroid:textSize15spandroid:layout_gravitycenterandroid:gravitycenter/android:idid/bmapViewandroid:layout_widthfill_parentandroid:layout_heightfill_parentandroid:clickabletrue /标注覆盖物实现代码如下/*** 根据手表的经纬度在地图上设置位置更新顶部的位置文字描述*/private void updateLocation(ArrayList list) {/*** 1. 新用户默认显示地址*/double lg 104.06; // 成都市的经纬度double lt 30.67;String location getResources().getString(R.string.fake_position);baiduMap.clear();List potions new ArrayList();for(int i list.size() -1; i 0 ; i--){// gps 非空则设置经纬度、位置的文字描述lg Double.parseDouble(list.get(i).getLongitude());lt Double.parseDouble(list.get(i).getLatitude());location list.get(i).getAddress();//地址太长处理下location location.replace(四川省,).replace(成都市,).replace(.,);final LatLng ll new LatLng(lt, lg); // 注意经纬度顺序/*** 为每个足迹依据先后顺序编号*/int image_id 0;switch (i){case 9: image_id R.mipmap.icon_mark1;break;case 8: image_id R.mipmap.icon_mark2;break;case 7: image_id R.mipmap.icon_mark3;break;case 6: image_id R.mipmap.icon_mark4;break;case 5: image_id R.mipmap.icon_mark5;break;case 4: image_id R.mipmap.icon_mark6;break;case 3: image_id R.mipmap.icon_mark7;break;case 2: image_id R.mipmap.icon_mark8;break;case 1: image_id R.mipmap.icon_mark9;break;case 0: image_id R.mipmap.icon_mark10;break;}BitmapDescriptor descriptor BitmapDescriptorFactory.fromResource(image_id);OverlayOptions options new MarkerOptions().position(ll).icon(descriptor).zIndex(i);Marker marker (Marker) baiduMap.addOverlay(options);//为marker添加识别标记信息Bundle bundle new Bundle();bundle.putSerializable(info, list.get(i));marker.setExtraInfo(bundle);MapStatusUpdate update MapStatusUpdateFactory.newLatLngZoom(ll,17);baiduMap.setMapStatus(update);}为标记的marker添加监听点击时实现弹出infowindow。(infowindow每次最多显示一条信息)/*** 为标记添加监听* 点击弹出地理位置信息*/baiduMap.setOnMarkerClickListener(new BaiduMap.OnMarkerClickListener() {Overridepublic boolean onMarkerClick(Marker marker) {// 获得marker中的数据GPSBean info (GPSBean) marker.getExtraInfo().get(info);// 生成一个TextView用户在地图中显示InfoWindowTextView location new TextView(getApplicationContext());location.setBackgroundResource(R.mipmap.gps_button);location.setPadding(15, 15, 8, 35);location.setTextColor(Color.DKGRAY);location.setText(定位时间 info.getUploadTime() \n info.getAddress());location.setTextSize(12);// 将marker所在的经纬度的信息转化成屏幕上的坐标final LatLng ll marker.getPosition();Point p baiduMap.getProjection().toScreenLocation(ll);p.y - 47;LatLng llInfo baiduMap.getProjection().fromScreenLocation(p);// 为弹出的InfoWindow添加点击事件mInfoWindow new InfoWindow(location,llInfo, new InfoWindow.OnInfoWindowClickListener() {Overridepublic void onInfoWindowClick() {baiduMap.hideInfoWindow();}});// 显示最后一条的InfoWindowbaiduMap.showInfoWindow(mInfoWindow);return true;}});最后将地图显示到最新的数据并且显示Infowindow。/*** 显示最后一个地理位置信息* 创建InfoWindow展示的view*/private void updateBaidumapInfowindown(String location,double lt, double lg){TextView textView new TextView(getApplicationContext());textView.setBackgroundResource(R.mipmap.gps_button);textView.setPadding(15, 15, 8, 35);textView.setTextColor(Color.DKGRAY);textView.setText(location);textView.setTextSize(12);final LatLng ll new LatLng(lt,lg);mInfoWindow new InfoWindow(textView, ll, new InfoWindow.OnInfoWindowClickListener() {Overridepublic void onInfoWindowClick() {baiduMap.hideInfoWindow();}});//显示InfoWindowbaiduMap.showInfoWindow(mInfoWindow);/*** 将地图视野移动最新的位置*/MapStatusUpdate update MapStatusUpdateFactory.newLatLngZoom(ll,17);baiduMap.setMapStatus(update);}至此可以完成。但是还有最重要的一点则是百度Api版本的问题本方法在新版本 3.4.1 似乎就不能用这种方法实现只能使用3.0.0版本。