概述
GitHub地址:https://github.com/LoveYourselfAndMe/GaoDeMapView
下面是全部代码复制粘贴即可
packagecom.cheyifu.businessapp.ui;
importandroid.graphics.BitmapFactory;
importandroid.graphics.Color;
importandroid.os.Bundle;
importandroid.os.SystemClock;
importandroid.support.v7.app.AppCompatActivity;
importandroid.util.Log;
importandroid.view.animation.CycleInterpolator;
importandroid.view.animation.Interpolator;
importandroid.view.animation.LinearInterpolator;
importcom.amap.api.location.AMapLocation;
importcom.amap.api.location.AMapLocationClient;
importcom.amap.api.location.AMapLocationClientOption;
importcom.amap.api.location.AMapLocationListener;
importcom.amap.api.maps.AMap;
importcom.amap.api.maps.CameraUpdateFactory;
importcom.amap.api.maps.LocationSource;
importcom.amap.api.maps.MapView;
importcom.amap.api.maps.UiSettings;
importcom.amap.api.maps.model.BitmapDescriptorFactory;
importcom.amap.api.maps.model.Circle;
importcom.amap.api.maps.model.CircleOptions;
importcom.amap.api.maps.model.LatLng;
importcom.amap.api.maps.model.Marker;
importcom.amap.api.maps.model.MarkerOptions;
importcom.cheyifu.businessapp.R;
importcom.cheyifu.businessapp.utils.SensorEventHelper;
importjava.util.Timer;
importjava.util.TimerTask;
public classMapActivityextendsAppCompatActivityimplementsLocationSource,
AMapLocationListener,AMap.OnMapLoadedListener,AMap.OnMapClickListener {
privateMapViewmapView;
privateAMapaMap;
privateUiSettingsmUiSettings;
privateOnLocationChangedListenermListener;
privateAMapLocationClientmlocationClient;
privateAMapLocationClientOptionmLocationOption;
// private static final int STROKE_COLOR = Color.argb(180, 3, 145, 255);
// private static final int FILL_COLOR = Color.argb(10, 0, 0, 180);
private booleanmFirstFix=false;
privateMarkermLocMarker;
privateSensorEventHelpermSensorHelper;
privateCirclemCircle;
privateCirclec;
privatecircleTaskmTimerTask;
private longstart;
privateTimermTimer=newTimer();
private finalInterpolatorinterpolator=newCycleInterpolator(1);
private finalInterpolatorinterpolator1=newLinearInterpolator();
privateCircleac;
@Override
protected voidonCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map);
mapView= (MapView) findViewById(R.id.mapview);
mapView.onCreate(savedInstanceState);
initMapView();
}
private voidinitMapView() {
if(aMap==null) {
aMap=mapView.getMap();
mUiSettings=aMap.getUiSettings();
}
setUpMap();
mSensorHelper=newSensorEventHelper(this);
if(mSensorHelper!=null) {
mSensorHelper.registerSensorListener();
}
}
/**
* 设置一些amap的属性
*/
private voidsetUpMap() {
aMap.setOnMapLoadedListener(this);
aMap.setOnMapClickListener(this);
aMap.setLocationSource(this);// 设置定位监听
//设置比例尺
mUiSettings.setScaleControlsEnabled(true);
//设置指南针
mUiSettings.setCompassEnabled(true);
//定位按钮
mUiSettings.setMyLocationButtonEnabled(true);
aMap.setMyLocationEnabled(true);
// 设置定位的类型为定位模式 ,可以由定位、跟随或地图根据面向方向旋转几种
aMap.setMyLocationType(AMap.LOCATION_TYPE_LOCATE);
}
@Override
protected voidonDestroy() {
super.onDestroy();
if(mLocMarker!=null) {
mLocMarker.destroy();
}
mapView.onDestroy();
if(null!=mlocationClient) {
mlocationClient.onDestroy();
}
if(mTimerTask!=null) {
mTimerTask.cancel();
mTimerTask=null;
}
try{
mTimer.cancel();
}catch(Throwable e) {
e.printStackTrace();
}
}
@Override
protected voidonResume() {
super.onResume();
mapView.onResume();
if(mSensorHelper!=null) {
mSensorHelper.registerSensorListener();
}
}
@Override
protected voidonPause() {
super.onPause();
if(mSensorHelper!=null) {
mSensorHelper.unRegisterSensorListener();
mSensorHelper.setCurrentMarker(null);
mSensorHelper=null;
}
mapView.onPause();
deactivate();
}
/**
* 停止定位
*/
@Override
public voiddeactivate() {
mListener=null;
if(mlocationClient!=null) {
mlocationClient.stopLocation();
mlocationClient.onDestroy();
}
mlocationClient=null;
}
@Override
protected voidonSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
mapView.onSaveInstanceState(outState);
}
@Override
public voidonLocationChanged(AMapLocation aMapLocation) {
if(mListener!=null&& aMapLocation !=null) {
if(mTimerTask!=null) {
mTimerTask.cancel();
mTimerTask=null;
}
if(aMapLocation !=null&& aMapLocation.getErrorCode() ==0) {
LatLng mylocation =newLatLng(aMapLocation.getLatitude(),
aMapLocation.getLongitude());
aMap.moveCamera(CameraUpdateFactory.newLatLngZoom(mylocation,18));
addLocationMarker(aMapLocation);
mSensorHelper.setCurrentMarker(mLocMarker);//定位图标旋转
}else{
String errText ="定位失败,"+ aMapLocation.getErrorCode() +": "
+ aMapLocation.getErrorInfo();
Log.e("AmapErr",errText);
}
}
}
private voidaddLocationMarker(AMapLocation aMapLocation) {
LatLng mylocation =newLatLng(aMapLocation.getLatitude(),aMapLocation.getLongitude());
floataccuracy = aMapLocation.getAccuracy();
if(mLocMarker==null) {
addMarker(mylocation);
ac=aMap.addCircle(newCircleOptions().center(mylocation)
.fillColor(Color.argb(100,255,218,185)).radius(accuracy)
.strokeColor(Color.argb(255,255,228,185)).strokeWidth(5));
c=aMap.addCircle(newCircleOptions().center(mylocation)
.fillColor(Color.argb(70,255,218,185))
.radius(accuracy).strokeColor(Color.argb(255,255,228,185))
.strokeWidth(0));
}else{
mLocMarker.setPosition(mylocation);
ac.setCenter(mylocation);
ac.setRadius(accuracy);
c.setCenter(mylocation);
c.setRadius(accuracy);
}
Scalecircle(c);
}
/**
* 开始定位。
*/
private voidstartlocation() {
if(mlocationClient==null) {
mlocationClient=newAMapLocationClient(this);
mLocationOption=newAMapLocationClientOption();
//设置定位监听
mlocationClient.setLocationListener(this);
//设置为高精度定位模式
mLocationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);
//设置定位时间
//是指定位间隔
mLocationOption.setInterval(10000);
//设置定位参数
mlocationClient.setLocationOption(mLocationOption);
// 此方法为每隔固定时间会发起一次定位请求,为了减少电量消耗或网络流量消耗,
// 注意设置合适的定位时间的间隔(最小间隔支持为2000ms),并且在合适时间调用stopLocation()方法来取消定位请求
// 在定位结束后,在合适的生命周期调用onDestroy()方法
// 在单次定位情况下,定位无论成功与否,都无需调用stopLocation()方法移除请求,定位sdk内部会移除
mlocationClient.startLocation();
}else{
mlocationClient.startLocation();
}
}
@Override
public voidactivate(OnLocationChangedListener listener) {
mListener= listener;
startlocation();
}
private voidaddMarker(LatLng latlng) {
if(mLocMarker!=null) {
return;
}
MarkerOptions options =newMarkerOptions();
options.icon(BitmapDescriptorFactory.fromBitmap(BitmapFactory.decodeResource(this.getResources(),
R.mipmap.navi_map_gps_locked)));
options.anchor(0.5f,0.5f);
options.position(latlng);
mLocMarker=aMap.addMarker(options);
// mLocMarker.setTitle(LOCATION_MARKER_FLAG);
}
@Override
public voidonMapClick(LatLng latLng) {
}
@Override
public voidonMapLoaded() {
}
public voidScalecircle(finalCircle circle) {
start= SystemClock.uptimeMillis();
mTimerTask=newcircleTask(circle,1000);
mTimer.schedule(mTimerTask,0,30);
}
private classcircleTaskextendsTimerTask {
private doubler;
privateCirclecircle;
private longduration=1000;
publiccircleTask(Circle circle, longrate) {
this.circle= circle;
this.r= circle.getRadius();
if(rate >0) {
this.duration= rate;
}
}
@Override
public voidrun() {
try{
longelapsed = SystemClock.uptimeMillis() -start;
floatinput = (float) elapsed /duration;
// 外圈循环缩放
// float t = interpolator.getInterpolation((float)(input-0.25));//return (float)(Math.sin(2 * mCycles * Math.PI * input))
// double r1 = (t + 2) * r;
// 外圈放大后消失
floatt =interpolator1.getInterpolation(input);
doubler1 = (t +1) *r;
circle.setRadius(r1);
if(input >2) {
start= SystemClock.uptimeMillis();
}
}catch(Throwable e) {
e.printStackTrace();
}
}
}
}
最后
以上就是谦让小松鼠为你收集整理的android 定位图标动画,高德地图图标随位置选转和放射动画效果的全部内容,希望文章能够帮你解决android 定位图标动画,高德地图图标随位置选转和放射动画效果所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复