地图打点,添加Marker

添加Marker的坐标处理

LatLng latLng = new LatLng(mLatl, mLong);
mLatl纬度(Latitude)
mLong经度(Longitude)
LatLng:存储经纬度坐标值的类,单位角度
LatLng(double latitude, double longitude)
使用传入的经纬度构造LatLng 对象,一对经纬度值代表地球上一个地点。

添加单个Marker

使用方法 MarkerOptions

markerOptions.add(new MarkerOptions()
        .anchor(0.5f, 0.5f)
        .position(latLng)
        .icon(BitmapDescriptorFactory.fromResource(R.mipmap.map_marker_station_unuse)));

add()添加marker
anchor(float u, float v)定义marker 图标的锚点。
position(LatLng position)设置当前MarkerOptions 对象的经纬度。
icon(BitmapDescriptor icon)设置MarkerOptions 对象的自定义图标。

批量添加Marker

定义一个ArrayList用来存放MarkerOptions对象

private ArrayList<MarkerOptions> markerOptionsList = new ArrayList<MarkerOptions>();

遍历markerOptionsList

markerOptionsList.add(new MarkerOptions()
            .anchor(0.5f, 0.5f)
            .position(latLng)
            .icon(BitmapDescriptorFactory.fromResource(R.mipmap.map_marker_station_unuse)));

定义Marker的List

List<Marker> markerlst;
批量添加
markerlst = aMap.addMarkers(markerOptionsList, true);
根据不同的状态或者种类来实现添加不同样式的marker,根据可以根据每个信息点的状态来判断然后实现不同类型使用不同style的marker,如下代码中的type和status就是根据每个marker点的状态和种类来判断的,将每个点的信息(包括坐标,icon)添加到markerOptionList中,然后在后面使用高德地图提高的批量添加marker的方法同意添加aMap.addMarkers

if (type == 0 && status == true) {
    //可预约
    markerOptionsList.add(new MarkerOptions()
            .position(latLng)
            .icon(BitmapDescriptorFactory.fromResource(R.mipmap.map_marker_pile)));
} else if (type == 0 && status == false) {
    //可控制
    markerOptionsList.add(new MarkerOptions()
            .anchor(0.5f, 0.5f)
            .position(latLng)
            .icon(BitmapDescriptorFactory.fromResource(R.mipmap.map_marker_station_unuse)));
} else if (type == 1 && status == true) {
    //可用
    markerOptionsList.add(new MarkerOptions()
            .anchor(0.5f, 0.5f)
            .position(latLng)
            .icon(BitmapDescriptorFactory.fromResource(R.mipmap.map_marker_station_use)));
} else if (type == 1 && status == false) {
    //不可用
    markerOptionsList.add(new MarkerOptions()
            .anchor(0.5f, 0.5f)
            .position(latLng)
            .icon(BitmapDescriptorFactory.fromResource(R.mipmap.map_marker_station_unuse)));
}
markerlst = aMap.addMarkers(markerOptionsList, true);
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

雪山上的小灰熊

谢谢支持哦

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值