上一篇博客介绍了地图的显示,不要太简单了, 我们要实现的效果当然不仅仅是显示地图这么废了, 现在地图是有了 , 怎么在地图上添加一个标注呢? 添加一个圆形?又或者是我想在地图上添加个自定义的View, 会不会很6? 呵呵
答案全在AMap aMap=mapView.getMap(); 我们添加的这些东西都是要在aMap上操作的 , 之前有说道定位回调的方法里面显示了系统的定位小蓝点 , 那我不想要那个效果咋整 ? 当然了SDK中的api可以修改定位点的样式 , 这个就不说了 , 对于强迫症的我来说 , 不如自己搞一个来的痛快, 系统定位蓝点不过就是个Marker而已
先来创建一个Marker , aMap.addMarker( ) 方法返回值就是Marker对象 , 方法参数接收的是 MarkerOptions ; MarkerOptions 可以设置资源图片 , 设置锚点 ,标题等等 ;重点说下这个图片MarkerOptions有个icon()方法 可以加载资源图片 , 也可以加载自定义View ; 有趣的是 ,api现在已经支持给Marker添加动画了 , 那就在添加Marker的同时 加入缩放和透明度渐变的动画
// BitmapDescriptorFactory.fromView(View view);
// BitmapDescriptorFactory.fromBitmap(Bitmap bitmap)
// BitmapDescriptorFactory.fromAsset(String s);
// BitmapDescriptorFactory.fromResource(int res);
// BitmapDescriptorFactory.fromFile(String path);
//加载一个layout
View view = View.inflate(this, R.layout.item_marker, null);
((TextView) view.findViewById(R.id.num)).setText("layout");
Marker addMarker = aMap.addMarker(new MarkerOptions()
.icon(BitmapDescriptorFactory.fromView(view))
.position(new LatLng(locationInfo.getLatitude(), locationInfo.getLongitude())));
//Marker 开启动画
private void startAnimation(Marker marker) {
AnimationSet animationSet = new AnimationSet(false);
Animation scale = new ScaleAnimation(0, 1, 0, 1);
Animation alpha = new AlphaAnimation(0, 1);
animationSet.addAnimation(alpha);
animationSet.addAnimation(scale);
animationSet.setDuration(300);
animationSet.setInterpolator(new LinearInterpolator());
marker.setAnimation(animationSet);
marker.startAnimation();
}
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center">
<ImageView
android:id="@+id/img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="@drawable/ic_location_blue_small" />
<TextView
android:id="@+id/num"
style="@style/text_10_color_1_style"
android:layout_gravity="center"
android:layout_marginBottom="6dp"
android:text="5"
android:textStyle="bold" />
</FrameLayout>
这样就可以在地图上面显示我们自定义的Marker了 , 那现在问题来了 , 如果我点击Marker会有什么效果呢 ? Marker点击事件需要设置监听才能响应 , 那就实现点击Marker放大的效果吧
非常坑爹的一个就是 , 并没有找到直接在原有Marker的基础上修改样式的方法 , 目前我是在点击Marker时 将之前的Marker移除掉 , 然后重新添加一个新的Marker , 以此来产生点击效果 ,
aMap.setOnMarkerClickListener(this);
@Override
public boolean onMarkerClick(Marker marker) {
//step 1 , reset 将上次的marker恢复到初始状态
if (markerPre != null && !marker.equals(markerPre) && markerIndexPre != -1) {
markerPre.remove();
View view = View.inflate(this, R.layout.item_marker, null);
((TextView) view.findViewById(R.id.num)).setText(String.valueOf(markerIndexPre));
((ImageView) view.findViewById(R.id.img)).setImageResource(R.drawable.ic_location_blue_small);
markers.put(markerIndexPre, aMap.addMarker(new MarkerOptions()
.icon(BitmapDescriptorFactory.fromView(view))
.position(markerPre.getPosition())));
}
if (!marker.equals(markerPre)) {
int clickIndex = -1;
for (Map.Entry<Integer, Marker> entry : markers.entrySet()) {
if (marker.equals(entry.getValue())) {
clickIndex = entry.getKey();
break;
}
}
if (clickIndex != -1) {
marker.remove();
View view = View.inflate(this, R.layout.item_marker, null);
((TextView) view.findViewById(R.id.num)).setText(String.valueOf(clickIndex));
((ImageView) view.findViewById(R.id.img)).setImageResource(R.drawable.ic_location_blue_big);
Marker addMarker = aMap.addMarker(new MarkerOptions()
.icon(BitmapDescriptorFactory.fromView(view))
.position(marker.getPosition()));
markers.put(clickIndex, addMarker);
startAnimation(addMarker);
recyclerView.smoothScrollToPosition(clickIndex - 1);
locationAdapter.refreshIndex(clickIndex - 1);
markerPre = addMarker;
markerIndexPre = clickIndex;
}
}
return false;
}
那地图上能不能绘制 圈儿圈儿 涅? 嘻嘻...api已经提供了方法 顾名思义 , 看到方法名就知道啥意思了
Circle circleOut = aMap.addCircle(new CircleOptions().center(latLng)//圈儿圈儿的坐标
.radius(maxRadius)//圈儿圈儿的半径R
.strokeColor(ContextCompat.getColor(this, android.R.color.transparent))
.fillColor(ContextCompat.getColor(this, R.color.blue_sharder))
.strokeWidth(0));
就画个圈儿圈儿会不会太单调了呀 , 要不干脆把系统的小蓝点干掉吧 , 自己写个圈儿圈儿补上 , 思路:外圈儿 套 内圈儿 , 内圈儿套 中心点 , 外圈儿半径R和中心点固定 , 内圈做动画通过不断的改变半径来实现雷达扫描的效果
private void refreshMyLocation(LatLng latLng) {
aMap.clear();
clearCircle();
// 绘制不同半径的圆,添加到地图上
final Circle circleOut = aMap.addCircle(new CircleOptions().center(latLng)
.radius(maxRadius)
.strokeColor(ContextCompat.getColor(this, android.R.color.transparent))
.fillColor(ContextCompat.getColor(this, R.color.blue_sharder))
.strokeWidth(0));
final Circle circleIn = aMap.addCircle(new CircleOptions().center(latLng)
.radius(10)
.strokeColor(ContextCompat.getColor(this, android.R.color.transparent))
.fillColor(ContextCompat.getColor(this, R.color.green_sharder))
.strokeWidth(0));
aMap.addMarker(new MarkerOptions()
.anchor(0.5f, 0.5f)
.setFlat(true)//平贴地面
.icon(BitmapDescriptorFactory.fromView(View.inflate(this, R.layout.item_location_point, null)))
.position(latLng));
listCircle.add(circleOut);
listCircle.add(circleIn);
startAnimator(circleIn);
}
private void clearCircle() {
if (valueAnimator != null && valueAnimator.isRunning()) {
valueAnimator.cancel();
}
for (int i = 0; i < listCircle.size(); i++) {
listCircle.get(i).remove();
listCircle.remove(i);
}
}
private void startAnimator(final Circle circle) {
valueAnimator = ValueAnimator.ofFloat(10, maxRadius).setDuration(3000);
valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
mAnimatorValue = (float) animation.getAnimatedValue();
circle.setRadius(mAnimatorValue);//在这里改变半径 不断绘制
}
});
valueAnimator.setRepeatCount(ValueAnimator.INFINITE);
valueAnimator.setRepeatMode(ValueAnimator.REVERSE);//反向重复执行,可以避免抖动
valueAnimator.start();
}
哈哈 , 还不错! 博客图片大小限制,压缩的有点模糊,凑活看吧
接下就是Poi 搜索了 , 话说Poi是个啥? Point of Interest兴趣点 , 就是个关键词搜索 , 这个是sdk自带的接口 , 返回与我们的关键词相关的一些数据
//查询条件
PoiSearch.Query(String keyWord,String p2,String cityCode) ;
keyWord表示搜索字符串
第二个参数表示POI搜索类型,二者选填其一,选用POI搜索类型时建议填写类型代码,码表可以参考下方(而非文字)
cityCode表示POI搜索区域,可以是城市编码也可以是城市名称,也可以传空字符串,空字符串代表全国在全国范围内进行搜索
//创建查询条件
PoiSearch.Query query = new PoiSearch.Query(keyWord, "", "");
if (poiSearch == null) {
poiSearch = new PoiSearch(MapActivity.this, query);
poiSearch.setOnPoiSearchListener(new PoiSearch.OnPoiSearchListener() {
@Override
public void onPoiSearched(PoiResult poiResult, int i) {
//搜索结果在这里解析
PoiItem poiItem = poiResult.getPois().get(j);
LatLonPoint latLonPoint = poiItem.getLatLonPoint();
latLng = new LatLng(latLonPoint.getLatitude(),
latLonPoint.getLongitude());
locationInfo = new LocationInfo();
locationInfo.setLatitude(latLonPoint.getLatitude());
locationInfo.setLongitude(latLonPoint.getLongitude());
locationInfo.setAddressName(poiItem.getTitle());
locationInfo.setAddress(poiItem.getAdName());
}
@Override
public void onPoiItemSearched(PoiItem poiItem, int i) {
}
});
} else {
poiSearch.setQuery(query);
}
//开始异步搜索
poiSearch.searchPOIAsyn();
可以从PoiItem 中获取坐标信息, poiItem.getTitle() 是Poi的名称 ,关于PoiItem的详细api可以参开开放平台的api的文档http://a.amap.com/lbs/static/unzip/Android_Map_Doc/index.html
来展示下最终的效果
文章浏览阅读1.6k次,点赞4次,收藏2次。短语a、b、aa、bb直接短语a、b句柄a所有产生式S->ABS | Aa | εA->aB->SBB | babbaa的最右推导S->ABS->ABAa->ABaa->ASBBaa->ASBbaa->ASbbaa->Abbaa->abbaa学如逆水行舟,不进则退..._生产式的句柄
文章浏览阅读790次。国标对接摄像头推送主码流还是子码流配置。(就是设备编号,不同设备加1即可)(外网的话我建议还是用tcp)网络-高级配置-平台接入。(与SIP用户名相同)_wvp-gb28181-pro 服务器配置要求
文章浏览阅读151次。����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������_android解答题面试题
文章浏览阅读4.7k次。Tomcat是Apache软件基金会 (Apache Software Foundation)的Jakarta项目中的一个核心项目,由Apache、Sun 和其他一些公司及个人共同开发而成.由于有了Sun的参与和支持,最新的Servlet和JSP规范总是能在Tomcat中得到体现,因为Tomcat 技术先进、性能稳定,而且免费,因而深受Java爱好者的喜爱并得到了部分软件开发商的认可,成为目前比较流行的Web应用服务器._apache和tomcat部署配置 网站
文章浏览阅读7.5k次,点赞12次,收藏36次。关于阴影深度的基础知识:传统的ShadowMapShadowMap说起来十分简单,把摄像机和光源的位置重叠,那么场景中该光源的阴影区域就是那些摄像机看不到的地方,主要应用在前向渲染路径中。具体实现分以下几个步骤:如果有平行光开启了阴影,Unity就会为该光源计算它的ShadowMap(只会计算一个平行光),这张ShadowMap其实就是深度图,记录了从该光源的位置出发、能看到的场景中距离它最近的表面位置(深度信息)。 Unity中实现了一个额外的Pass来专门更新光源的ShadowMap,_transfer_shadow
文章浏览阅读1.7w次。写好一个Web项目想部署到Linux上运行一下,把Tomcat、Mysql、JDK等环境搭好后,访问Tomcat欢迎页面正常,访问ip:端口/项目名却显示404。找了好久,修改Tomcat配置文件等等措施都试过了,都无效。最后新建一个空项目,只包含一个jsp,访问成功。在项目中新建一个Servlet,再次访问,报500错误,报UnsupportedClassVersionError异常,_linux下启动tomcat访问html报错404
文章浏览阅读103次。“/cwfx”应用程序中的服务器错误。无法初始化链接服务器 "(null)" 的 OLE DB 访问接口 "MICROSOFT.JET.OLEDB.4.0" 的数据源对象。说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.Exception: 无法初始化链接服务..._abel4.0
文章浏览阅读532次,点赞28次,收藏30次。为了做好运维面试路上的助攻手,特整理了上百道。_csdn 新购的云服务器怎么使用
文章浏览阅读2.7w次。目前能想到的用途是不侵犯他人肖像权的情况下做些假数据,展示性的数据。每次刷新ai都会随机生成一张头像。真人头像,欧美偏多,亚洲面孔少:https://thispersondoesnotexist.com/二次元女生头像:https://www.thiswaifudoesnotexist.net/..._生成ai人物的网站
文章浏览阅读2.7k次,点赞2次,收藏8次。# Go 安装包前提1. 所有包的安装下载都必须开启 go mod,并且 Go 版本需要大于 1.11 - `go env -w GO111MODULE=on`2. 包下载和安装需要在GOPATH 下一个项目内进行_go 离线安装包
文章浏览阅读2.6k次。MATLAB R2016b 静默安装、激活(Ubuntu 16.04)概要无图形界面环境下,静默安装、激活MATLAB。R2016b的iso安装包分两份,静默安装时需要合并为一份,否则要处理换碟问题。注意:本文的所有命令使用root权限执行。系统环境Ubuntu 16.04文件准备下载安装包(放置在”~/Matlab/”目录下): 1. R2016b_glnxa6..._matlabr2016激活
文章浏览阅读2.5k次,点赞2次,收藏16次。这是一份来自和鲸社区的倒闭企业数据集,总计 6,272 条记录,大小为 2.3 M,包含 21 个字段。_6000条倒闭企业数据分析