在高德地图上添加自定义Marker

在高德地图上添加自定义Marker_第1张图片
    public void showCityAtMap(MapView mapView) {
        if (aMap == null) {
            aMap = mapView.getMap();
        }
        aMap.clear();
        aMap.moveCamera(CameraUpdateFactory.zoomTo(5));
        ArrayList allCity = (ArrayList) DataSupport.findAll(WeatherDataInfo.class);
        for (WeatherDataInfo weatherDataInfo : allCity) {
            LatLng latLng = new LatLng(weatherDataInfo.getLat(), weatherDataInfo.getLon());
            aMap.addMarker(new MarkerOptions().position(latLng).draggable(false).snippet(""+weatherDataInfo.getPosition())
                    .icon(BitmapDescriptorFactory.fromView(
                                    getInfoWindow(weatherDataInfo.getName(),
                                            weatherDataInfo.getTmp(),
                                            weatherDataInfo.getIcon()))));
        }
        aMap.setOnMarkerClickListener(new AMap.OnMarkerClickListener() {
            @Override
            public boolean onMarkerClick(Marker marker) {
                listener.onWindowClick(Integer.parseInt(marker.getSnippet()));
                return true;
            }
        });
    }

主要是利用addMarker方法添加一个Marker,但Marker的样式为自定义的View:

    public View getInfoWindow(String city, String temp, int icon) {
        View view = View.inflate(BaseUtils.getContext(), R.layout.marker_info_layout, null);
        TextView tvCity = (TextView) view.findViewById(R.id.tv_city);
        TextView tvTemp = (TextView) view.findViewById(R.id.tv_temp);
        ImageView ivIcon = (ImageView) view.findViewById(R.id.iv_icon);
        tvCity.setText(city);
        tvTemp.setText(temp);
        ivIcon.setImageResource(icon);
        return view;
    }

布局:


    
        
    
    
        
        
    

你可能感兴趣的:(在高德地图上添加自定义Marker)