zoukankan      html  css  js  c++  java
  • 百度地图3.7.1添加覆盖物

    首先应该请求网络得到一些信息,比如要添加覆盖物的经度纬度,介绍啊之类的,然后就是怎么来添加覆盖物了。

    private void addMarker(List<Info> infos) {
            //清掉地图上的图层
            mBaidu.clear();
            LatLng la = null;
            //声明覆盖物
            Marker marker = null;
            //覆盖层对象
            OverlayOptions options = null;
            for (Info info : infos) {
                la = new LatLng(info.getLatitude(), info.getLongitude());
                //设置覆盖层的经纬,和图标,和底基层
                options = new MarkerOptions().icon(mMarker).position(la).zIndex(5);
                //加入层
                marker = (Marker) mBaidu.addOverlay(options);
                //传递值,为了点击事件
                Bundle b = new Bundle();
                b.putSerializable("info",info);
                marker.setExtraInfo(b);
            }
            //设置地图到最后一个位置
            MapStatusUpdate msu = MapStatusUpdateFactory.newLatLng(la);
            mBaidu.setMapStatus(msu);
        }

    点击事件

    mBaidu.setOnMarkerClickListener(new OnMarkerClickListener() {
                
                @Override
                public boolean onMarkerClick(Marker marker) {
                    Bundle extraInfo = marker.getExtraInfo();
                    Info info = (Info) extraInfo.getSerializable("info");
                    ImageView iv = (ImageView) mMarkerLy
                            .findViewById(R.id.id_info_img);
                    TextView distance = (TextView) mMarkerLy
                            .findViewById(R.id.id_info_distance);
                    TextView name = (TextView) mMarkerLy
                            .findViewById(R.id.id_info_name);
                    TextView zan = (TextView) mMarkerLy
                            .findViewById(R.id.id_info_zan);
                    iv.setImageResource(info.getImgId());
                    distance.setText(info.getDistance());
                    name.setText(info.getName());
                    zan.setText(info.getZan() + "");
                    mMarkerLy.setVisibility(View.VISIBLE);
                    
                    return true;
                }
            });
        //地图点击事件
            mBaidu.setOnMapClickListener(new OnMapClickListener() {
                
                @Override
                public boolean onMapPoiClick(MapPoi arg0) {
                    // TODO Auto-generated method stub
                    return false;
                }
                
                @Override
                public void onMapClick(LatLng arg0) {
                    mMarkerLy.setVisibility(View.GONE);
                    //隐藏
                    mBaidu.hideInfoWindow();
                    
                }
            });
    package com.map.ditu;
    
    import java.io.Serializable;
    import java.util.ArrayList;
    import java.util.List;
    
    public class Info implements Serializable
    {
        private static final long serialVersionUID = -1010711775392052966L;
        private double latitude;
        private double longitude;
        private int imgId;
        private String name;
        private String distance;
        private int zan;
    
        public static List<Info> infos = new ArrayList<Info>();
    
        static
        {
            infos.add(new Info(34.242652, 108.971171, R.drawable.a01, "Ӣ�׹���С�ù�",
                    "����209��", 1456));
            infos.add(new Info(34.242952, 108.972171, R.drawable.a02, "ɳ�����ϴԡ����",
                    "����897��", 456));
            infos.add(new Info(34.242852, 108.973171, R.drawable.a03, "�廷��װ��",
                    "����249��", 1456));
            infos.add(new Info(34.242152, 108.971971, R.drawable.a04, "���׼�����С��",
                    "����679��", 1456));
        }
    
        public Info(double latitude, double longitude, int imgId, String name,
                String distance, int zan)
        {
            this.latitude = latitude;
            this.longitude = longitude;
            this.imgId = imgId;
            this.name = name;
            this.distance = distance;
            this.zan = zan;
        }
    
        public double getLatitude()
        {
            return latitude;
        }
    
        public void setLatitude(double latitude)
        {
            this.latitude = latitude;
        }
    
        public double getLongitude()
        {
            return longitude;
        }
    
        public void setLongitude(double longitude)
        {
            this.longitude = longitude;
        }
    
        public int getImgId()
        {
            return imgId;
        }
    
        public void setImgId(int imgId)
        {
            this.imgId = imgId;
        }
    
        public String getName()
        {
            return name;
        }
    
        public void setName(String name)
        {
            this.name = name;
        }
    
        public String getDistance()
        {
            return distance;
        }
    
        public void setDistance(String distance)
        {
            this.distance = distance;
        }
    
        public int getZan()
        {
            return zan;
        }
    
        public void setZan(int zan)
        {
            this.zan = zan;
        }
    
    }
  • 相关阅读:
    [root@py ~]# watch -n 1 ifconfig 求解释
    25 个常用的 Linux iptables 规则
    linux shell 字符串操作(长度,查找,替换)详解
    linux高级网络配置 ip别名,接口绑定
    初始版本控制工具-Git
    详解 TCP 连接的“ 三次握手 ”与“ 四次挥手 ”
    wireshark_users
    wireshark抓包基础步骤及PPPOE拨号抓包过程分析
    ARP原理与ARP攻击
    PPPOE 详解
  • 原文地址:https://www.cnblogs.com/84126858jmz/p/5377212.html
Copyright © 2011-2022 走看看