Pony,仿支付宝到位动态加载marker效果

来源:互联网 发布:淘宝会员名怎么注册 编辑:程序博客网 时间:2024/05/20 03:43

使用到的知识点:

1:高德地图定位;

2:高德地图poi搜索;

3:动态监测地图中心位置的坐标;

4:添加marker


实现步骤:


1:在进入主界面的时候先进行定位的操作,为的就是显示的poi的信息是自己附近的poi的信息;


/** * 定位成功后回调函数 */@Overridepublic void onLocationChanged(AMapLocation amapLocation) {amapLocation.getAddress();if (mListener != null && amapLocation != null) {if (amapLocation != null && amapLocation.getErrorCode() == 0) {aMapLocationMessage = amapLocation;LatLng location = new LatLng(amapLocation.getLatitude(), amapLocation.getLongitude());if (!mFirstFix) {mFirstFix = true;addCircle(location, amapLocation.getAccuracy());// 添加定位精度圆addMarker(location);// 添加定位图标mSensorHelper.setCurrentMarker(mLocMarker);// 定位图标旋转aMap.moveCamera(CameraUpdateFactory.newLatLngZoom(location, 18));doSearchQuery(new LatLonPoint(location.longitude, location.latitude));} else {mCircle.setCenter(location);mCircle.setRadius(amapLocation.getAccuracy());mLocMarker.setPosition(location);}} else {String errText = "定位失败," + amapLocation.getErrorCode() + ": " + amapLocation.getErrorInfo();Log.i("AmapErr", errText);}}}



2:进行poi的搜索;

/** * 开始进行poi搜索 */protected void doSearchQuery(LatLonPoint lp) {currentPage = 0;
query = new PoiSearch.Query("公园", "", "");// 第一个参数表示搜索字符串,第二个参数表示poi搜索类型,第三个参数表示poi搜索区域(空字符串代表全国)query.setPageSize(20);// 设置每页最多返回多少条poiitemquery.setPageNum(currentPage);// 设置查第一页if (lp != null) {poiSearch = new PoiSearch(this, query);poiSearch.setOnPoiSearchListener(this);poiSearch.setBound(new SearchBound(lp, 2500, true));//// 设置搜索区域为以lp点为圆心,其周围2500米范围poiSearch.searchPOIAsyn();// 异步搜索}}

3:对搜索的结果添加marker的操作;

@Overridepublic void onPoiSearched(PoiResult result, int rcode) {if (rcode == 1000) {if (result != null && result.getQuery() != null) {// 搜索poi的结果if (result.getQuery().equals(query)) {// 是否是同一条poiResult = result;poiItems = poiResult.getPois();// 取得第一页的poiitem数据,页数从数字0开始List<SuggestionCity> suggestionCities = poiResult.getSearchSuggestionCitys();// 当搜索不到poiitem数据时,会返回含有搜索关键字的城市信息if (poiItems != null && poiItems.size() > 0) {if (poiItems != null && poiItems.size() > 0) {
myPoiOverlay poiOverlay = new myPoiOverlay(aMap, poiItems);poiOverlay.removeFromMap();poiOverlay.addToMap();// poiOverlay.zoomToSpan();} else if (suggestionCities != null && suggestionCities.size() > 0) {showSuggestCity(suggestionCities);} else {//ToastUtil.ShowCentre(MainActivity.this, "对不起,没有搜索到相关数据");}}}}}}

4:把布局文件作为marker的样式;

protected BitmapDescriptor getBitmapDescriptor(int arg0) {if (arg0 < 10) {View view = LayoutInflater.from(MainActivity.this).inflate(R.layout.marker_item, null);return BitmapDescriptorFactory.fromView(view);} else {View view = LayoutInflater.from(MainActivity.this).inflate(R.layout.marker_no, null);return BitmapDescriptorFactory.fromView(view);}}

5:对地图移动的检测;


aMap.setOnCameraChangeListener(this);


6:对移动检测的回调方法进行数据处理;

@Overridepublic void onCameraChange(CameraPosition position) {LatLng target = position.target;// Log.e("pony_log", target.latitude + "jinjin------" +// target.longitude);}@Overridepublic void onCameraChangeFinish(CameraPosition position) {// TODO Auto-generated method stubLatLng target = position.target;doSearchQuery(new LatLonPoint(target.longitude, target.latitude));Log.e("pony_log", target.latitude + "jinjin------" + target.longitude);}

至此,这块的逻辑功能就完成了;


效果就是:

          


源码在此,供大家交流:

源码地址



0 0