摘要:先上效果定位拖動(dòng)定位定位動(dòng)畫動(dòng)畫結(jié)束顯示地址實(shí)現(xiàn)思路中心點(diǎn)不變,在百度地圖圖層上覆蓋自定義的定位布局拖動(dòng)地圖時(shí),隱藏地址顯示,定位標(biāo)示落下來后顯示地址拿到百度地圖的拖動(dòng)監(jiān)聽拿到中心點(diǎn)經(jīng)緯度,逆地理編碼即坐標(biāo)轉(zhuǎn)地址具體實(shí)現(xiàn)布局在主界面布局上覆
先上效果:
定位+拖動(dòng)定位
定位動(dòng)畫
動(dòng)畫結(jié)束顯示地址
實(shí)現(xiàn)思路中心點(diǎn)不變,在百度地圖圖層上覆蓋自定義的定位布局
(TextView+I(xiàn)mageView+I(xiàn)mageView)
拖動(dòng)地圖時(shí),隱藏地址顯示,定位標(biāo)示落下來后顯示地址
拿到百度地圖的拖動(dòng)監(jiān)聽 setOnMapStatusChangeListener
拿到中心點(diǎn)經(jīng)緯度,逆地理編碼(即坐標(biāo)轉(zhuǎn)地址)mapStatus.target
具體實(shí)現(xiàn): 布局:在主界面布局上覆蓋自己定位用的布局location_marker
location_marker布局:三個(gè)控件
拖動(dòng)監(jiān)聽
創(chuàng)建地理編碼檢索實(shí)例;
創(chuàng)建地理編碼檢索監(jiān)聽者;
開始向上的動(dòng)畫
停止拖動(dòng)后,發(fā)起地理編碼檢索
mBaiduMap.setOnMapStatusChangeListener(new BaiduMap.OnMapStatusChangeListener() { @Override public void onMapStatusChangeStart(MapStatus mapStatus) { mSearch = GeoCoder.newInstance(); mSearch.setOnGetGeoCodeResultListener(listener); startUpAnimation(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { //動(dòng)畫開始時(shí),隱藏地址顯示 tv_describe.setVisibility(View.INVISIBLE); } @Override public void onAnimationEnd(Animation animation) { } @Override public void onAnimationRepeat(Animation animation) { } }); } @Override public void onMapStatusChangeStart(MapStatus mapStatus, int i) { } @Override public void onMapStatusChange(MapStatus mapStatus) { } @Override public void onMapStatusChangeFinish(MapStatus mapStatus) { mSearch.reverseGeoCode(new ReverseGeoCodeOption() .location(mapStatus.target)); } });
地理位置編碼檢索監(jiān)聽實(shí)現(xiàn):
OnGetGeoCoderResultListener listener = new OnGetGeoCoderResultListener() { public void onGetGeoCodeResult(GeoCodeResult result) { if (result == null || result.error != SearchResult.ERRORNO.NO_ERROR) { //沒有檢索到結(jié)果 } //獲取地理編碼結(jié)果 } @Override public void onGetReverseGeoCodeResult(ReverseGeoCodeResult result) { if (result == null || result.error != SearchResult.ERRORNO.NO_ERROR) { //沒有找到檢索結(jié)果 Toast.makeText(MainActivity.this,"沒有找到檢索結(jié)果",Toast.LENGTH_SHORT).show(); } //獲取反向地理編碼結(jié)果 String address = result.getAddress(); System.out.println(address+"---------"); tv_describe.setText(address); startDownAnimation(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { tv_describe.setVisibility(View.VISIBLE); bounce(); } @Override public void onAnimationRepeat(Animation animation) { } }); } };三種動(dòng)畫的具體實(shí)現(xiàn):
需要一個(gè)變量紀(jì)錄是否向上
private boolean isUp = false; /** * 向上移動(dòng)動(dòng)畫 */ public void startUpAnimation(Animation.AnimationListener listener){ if (isUp){ return; } Animation animation = new TranslateAnimation( 0, 0, 0 , - 80); animation.setDuration(500); animation.setFillAfter(true);//設(shè)置為true,動(dòng)畫轉(zhuǎn)化結(jié)束后被應(yīng)用 animation.setInterpolator(new AccelerateDecelerateInterpolator()); iv_location.startAnimation(animation);//開始動(dòng)畫 if(listener != null){ animation.setAnimationListener(listener); } isUp = true; } /** * 向下移動(dòng)動(dòng)畫 */ public void startDownAnimation(Animation.AnimationListener listener){ if(isUp){ Animation animation = new TranslateAnimation( 0, 0, -80, 0); animation.setDuration(500); animation.setFillAfter(true);//設(shè)置為true,動(dòng)畫轉(zhuǎn)化結(jié)束后被應(yīng)用 animation.setInterpolator(new AccelerateInterpolator(15)); if(listener != null){ animation.setAnimationListener(listener); } iv_location.startAnimation(animation);//開始動(dòng)畫 isUp = false; } } /** * 彈跳動(dòng)畫 */ public void bounce() { if (iv_location.getVisibility() == View.VISIBLE) { ObjectAnimator animator = ObjectAnimator.ofFloat(iv_location, "translationY", 0, -30, 0); animator.setInterpolator(new EasingInterpolator(EasingInterpolator.Ease.ELASTIC_IN_OUT)); animator.setDuration(1000); animator.setRepeatMode(ValueAnimator.REVERSE); animator.start(); } }定位方面參考之前文章,更新一下之前寫的MyLocationListener
新添加一個(gè)變量紀(jì)錄是否第一次定位
private boolean isFirst = true; class MyLocationListener extends BDAbstractLocationListener { @Override public void onReceiveLocation(BDLocation bdLocation) { MyLocationData locData = new MyLocationData.Builder() .accuracy(bdLocation.getRadius()) // 此處設(shè)置開發(fā)者獲取到的方向信息,順時(shí)針0-360 .direction(bdLocation.getDirection()).latitude(bdLocation.getLatitude()) .longitude(bdLocation.getLongitude()).build(); mBaiduMap.setMyLocationData(locData); String addr = bdLocation.getAddrStr(); //獲取詳細(xì)地址信息 String country = bdLocation.getCountry(); //獲取國家 String province = bdLocation.getProvince(); //獲取省份 String city = bdLocation.getCity(); //獲取城市 String district = bdLocation.getDistrict(); //獲取區(qū)縣 String street = bdLocation.getStreet(); //獲取街道信息 // showMyLocate(locData); if(isFirst){ // 開始移動(dòng)百度地圖的定位地點(diǎn)到中心位置 LatLng ll = new LatLng(bdLocation.getLatitude(), bdLocation.getLongitude()); MapStatusUpdate u = MapStatusUpdateFactory.newLatLngZoom(ll,16); mBaiduMap.animateMapStatus(u); isFirst = false; } } } }
文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉(zhuǎn)載請(qǐng)注明本文地址:http://systransis.cn/yun/71419.html
眾所周知,Python的一個(gè)使用場(chǎng)景還是比較多的,在工作當(dāng)中,也會(huì)涉及到多方面的一些事情。那么,今天小編寫這篇文章的一個(gè)主要目的,給大家來介紹關(guān)于如何用Python完成百度與搞得地圖轉(zhuǎn)換,下面就給大家詳細(xì)介紹下?! ∫?、地理編碼與逆編碼 地理編碼與逆編碼表示的是地名地址與地理坐標(biāo)(經(jīng)緯度)互相轉(zhuǎn)換的過程。其中,將地址信息映射為地理坐標(biāo)的過程稱之為地理編碼;將地理坐標(biāo)轉(zhuǎn)換為地址信息的過程稱之為...
閱讀 1713·2021-11-24 09:39
閱讀 2497·2021-11-18 10:07
閱讀 3678·2021-08-31 09:40
閱讀 3352·2019-08-30 15:44
閱讀 2642·2019-08-30 12:50
閱讀 3665·2019-08-26 17:04
閱讀 1441·2019-08-26 13:49
閱讀 1279·2019-08-23 18:05