@Override
public void onReceiveLocation(BDLocation location) {
//定位方向
mCurrentLat = location.getLatitude();
mCurrentLon = location.getLongitude();
//个人定位
locData = new MyLocationData.Builder()
.direction(mCurrentDirection).latitude(location.getLatitude())
.longitude(location.getLongitude()).build();
mBaiduMap.setMyLocationData(locData);
mBaiduMap.setMyLocationConfiguration(new MyLocationConfiguration(
MyLocationConfiguration.LocationMode.NORMAL, true, null));
//更改UI
Message message = new Message();
message.obj = location;
mHandler.sendMessage(message);
}
};
###第三步:更改UI
//设置打卡目标范围圈
private void setCircleOptions() {
if (mDestinationPoint == null) return;//打卡坐标不能为空
OverlayOptions ooCircle = new CircleOptions().fillColor(0x4057FFF8)
.center(mDestinationPoint).stroke(new Stroke(1, 0xB6FFFFFF)).radius(DISTANCE);
mBaiduMap.addOverlay(ooCircle);
}
/**
- 添加地图文字
- @param point
- @param str
- @param color 字体颜色
*/
private void setTextOption(LatLng point, String str, String color) {
//使用MakerInfoWindow
if (point == null) return;
TextView view = new TextView(getApplicationContext());
view.setBackgroundResource(R.mipmap.map_textbg);
view.setPadding(0, 23, 0, 0);
view.setTypeface(Typeface.DEFAULT_BOLD);
view.setTextSize(14);
view.setGravity(Gravity.CENTER);
view.setText(str);
view.setTextColor(Color.parseColor(color));
mInfoWindow = new InfoWindow(view, point, 170);
mBaiduMap.showInfoWindow(mInfoWindow);
}
/**
- 设置marker覆盖物
- @param ll 坐标
- @param icon 图标
*/
private void setMarkerOptions(LatLng ll, int icon) {
if (ll == null) return;
BitmapDescriptor bitmap = BitmapDescriptorFactory.fromResource(icon);
MarkerOptions ooD = new MarkerOptions().position(ll).icon(bitmap);
mBaiduMap.addOverlay(ooD);
}
//改变地图缩放
private void setMapZoomScale(LatLng ll) {
if (mDestinationPoint == null) {//打卡坐标不为空
mZoomScale = getZoomScale(ll);
mBaiduMap.animateMapStatus(MapStatusUpdateFactory.newLatLngZoom(ll, mZoomScale));//缩放
} else {
mZoomScale = getZoomScale(ll);
mBaiduMap.animateMapStatus(MapStatusUpdateFactory.newLatLngZoom(mCenterPos, mZoomScale));//缩放
}
}
/**
- 获取地图的中心点和缩放比例
- @return float
*/
private float getZoomScale(LatLng LocationPoint) {
double maxLong; //最大经度
double minLong; //最小经度
double maxLat; //最大纬度
double minLat; //最小纬度
List longItems = new ArrayList(); //经度集合
List latItems = new ArrayList(); //纬度集合
if (null != LocationPoint) {
longItems.add(LocationPoint.longitude);
latItems.add(LocationPoint.latitude);
}
if (null != mDestinationPoint) {
longItems.add(mDestinationPoint.longitude);
latItems.add(mDestinationPoint.latitude);
}
maxLong = longItems.get(0); //最大经度
minLong = longItems.get(0); //最小经度
maxLat = latItems.get(0); //最大纬度
minLat = latItems.get(0); //最小纬度
for (int i = 0; i < longItems.size(); i++) {
maxLong = Math.max(maxLong, longItems.get(i)); //获取集合中的最大经度
minLong = Math.min(minLong, longItems.get(i)); //获取集合中的最小经度
}
for (int i = 0; i < latItems.size(); i++) {
maxLat = Math.max(maxLat, latItems.get(i)); //获取集合中的最大纬度
minLat = Math.min(minLat, latItems.get(i)); //获取集合中的最小纬度
}
double latCenter = (maxLat + minLat) / 2;
double longCenter = (maxLong + minLong) / 2;
int jl = (int) getDistance(new LatLng(maxLat, maxLong), new LatLng(minLat, minLong));//缩放比例参数
mCenterPos = new LatLng(latCenter, longCenter); //获取中心点经纬度
int zoomLevel[] = {2500000, 2000000, 1000000, 500000, 200000, 100000,
50000, 25000, 20000, 10000, 5000, 2000, 1000, 500, 100, 50, 20, 0};
int i;
for (i = 0; i < 18; i++) {
if (zoomLevel[i] < jl) {
break;
}
}
float zoom = i + 4;
return zoom;
}
/**
- 缩放比例参数
- @param var0
- @param var1
- @return
*/
public double getDistance(LatLng var0, LatLng var1) {
if (var0 != null && var1 != null) {
Point var2 = CoordUtil.ll2point(var0);
Point var3 = CoordUtil.ll2point(var1);
return var2 != null && var3 != null ? CoordUtil.getDistance(var2, var3) : -1.0D;
} else {
return -1.0D;
}
}
/**
- 处理连续定位的地图UI变化
*/
private Handler mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
BDLocation location = (BDLocation) msg.obj;
LatLng LocationPoint = new LatLng(location.getLatitude(), location.getLongitude());
//打卡范围
mDestinationPoint = new LatLng(location.getLatitude() * 1.0001, location.getLongitude() * 1.0001);//假设公司坐标
setCircleOptions();
//计算两点距离,单位:米
mDistance = DistanceUtil.getDistance(mDestinationPoint, LocationPoint);
if (mDistance <= DISTANCE) {
//显示文字
setTextOption(mDestinationPoint, “您已在餐厅范围内”, “#7ED321”);
//目的地图标
setMarkerOptions(mDestinationPoint, R.mipmap.arrive_icon);
//按钮颜色
//commit_bt.setBackgroundDrawable(getResources().getDrawable(R.mipmap.restaurant_btbg_yellow));
mBaiduMap.setMyLocationEnabled(false);
自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。
深知大多数Android工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则几千的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!
因此收集整理了一份《2024年Android移动开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Android开发知识点,真正体系化!
由于文件比较大,这里只是将部分目录大纲截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且后续会持续更新
如果你觉得这些内容对你有帮助,可以添加V获取:vip204888 (备注Android)
最后
其实要轻松掌握很简单,要点就两个:
- 找到一套好的视频资料,紧跟大牛梳理好的知识框架进行学习。
- 多练。 (视频优势是互动感强,容易集中注意力)
你不需要是天才,也不需要具备强悍的天赋,只要做到这两点,短期内成功的概率是非常高的。
对于很多初中级Android工程师而言,想要提升技能,往往是自己摸索成长,不成体系的学习效果低效漫长且无助。
阿里P7Android高级教程
下面资料部分截图,诚意满满:特别适合有3-5年开发经验的Android程序员们学习。
附送高清脑图,高清知识点讲解教程,以及一些面试真题及答案解析。送给需要的提升技术、近期面试跳槽、自身职业规划迷茫的朋友们。
Android核心高级技术PDF资料,BAT大厂面试真题解析;
5年开发经验的Android程序员们学习。**
[外链图片转存中…(img-M6SB2WAN-1711732736938)]
附送高清脑图,高清知识点讲解教程,以及一些面试真题及答案解析。送给需要的提升技术、近期面试跳槽、自身职业规划迷茫的朋友们。
Android核心高级技术PDF资料,BAT大厂面试真题解析;
[外链图片转存中…(img-LVRJWIMR-1711732736938)]