栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

使标记带有自定义信息,以供单击时使用(Android,Google Maps v2)

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

使标记带有自定义信息,以供单击时使用(Android,Google Maps v2)

尝试这种方式,希望能帮助您解决问题。

定义一个以 Marker* 为键并以 alert 为值的 HashMap ,并在创建新Marker时添加到地图上时,将该
Marker 作为键添加到HashMap中,并从 alertList中 添加相应的 alert 数据,单击特定的
Marker 信息窗口时,从 HashMap中 获取特定的 alert 数据。

*


public class alertViewonMap extends Activity {    //declarations    ArrayList<String> dateCreatedAtList = new ArrayList<String>();    TextView busNumberTextView;    TextView descriptionTextView;    TextView alertTimeTextView;    DateFormat dateFormat = new SimpleDateFormat("HH:mm");    private HashMap<Marker,alert> markerDataMap;    protected void onCreate(Bundle savedInstanceState) {        // TODO Auto-generated method stub        super.onCreate(savedInstanceState);        this.setContentView(com.fourbox.bocterapp.R.layout.details_design);        busNumberTextView = (TextView) findViewById(R.id.textViewalertBusNumber);        descriptionTextView = (TextView) findViewById(R.id.textViewalertDescription);        alertTimeTextView = (TextView) findViewById(R.id.textViewalertTime);        busNumber = getIntent().getIntExtra("busNumber", 0);        description = getIntent().getStringExtra("description");        coordinatesLatitude =  getIntent().getDoubleExtra("coordinatesLatitude", 0);        coordinatesLongitude = getIntent().getDoubleExtra("coordinatesLongitude", 0);        alertTime.setTime(getIntent().getLongExtra("createdAt", 0));        busNumberList = getIntent().getStringArrayListExtra("busNumberList");        descriptionList = getIntent().getStringArrayListExtra("descriptionList");        coordinatesLatitudeList =     getIntent().getStringArrayListExtra("coordinatesLatitudeList");        coordinatesLongitudeList =     getIntent().getStringArrayListExtra("coordinatesLongitudeList");        dateCreatedAtList = getIntent().getStringArrayListExtra("dateCreatedAtList");        GoogleMap mMap;        mMap = ((MapFragment)     getFragmentManager().findFragmentById(com.fourbox.bocterapp.R.id.mapFragment)).getMap();        reunitealertListFromGetExtra();        placeAllMarkersonMap(mMap, alertsList);        LatLng latLng = new LatLng(coordinatesLatitude, coordinatesLongitude);        CameraPosition cameraPosition = new CameraPosition.Builder()     .target(latLng) // Center Set     .zoom(18.0f)     // Zoom     .bearing(0)     // Orientation of the camera to east     .tilt(30)        // Tilt of the camera to 30 degrees     .build();        // Creates a CameraPosition from the builder        mMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));        busNumberTextView.setText(String.valueOf(busNumber));        descriptionTextView.setText(description);        alertTimeTextView.setText(String.valueOf(dateFormat.format(alertTime)));    }    public void placeAllMarkersonMap(GoogleMap mMap, ArrayList<alert> alertsList) {        markerDataMap = new HashMap<Marker, alert>();        for(int i=0; i<alertsList.size(); i++) { markerDataMap.put(mMap.addMarker(new MarkerOptions()         .position(new     LatLng(alertsList.get(i).getCoordinates().getLatitude(),     alertsList.get(i).getCoordinates().getLongitude()))         .title(alertsList.get(i).getDescription())         .snippet(String.valueOf(alertsList.get(i).getBusNumber())         )),alertsList.get(i));        }    }    public void reunitealertListFromGetExtra() {        for (int i =0; i<busNumberList.size(); i++) { alert alert = new alert(); ParseGeoPoint parseGeoPoint = new ParseGeoPoint(); parseGeoPoint.setLatitude(Double.valueOf(coordinatesLatitudeList.get(i))); parseGeoPoint.setLongitude(Double.valueOf(coordinatesLongitudeList.get(i))); alert.setBusNumber(Integer.valueOf(busNumberList.get(i))); alert.setDescription(descriptionList.get(i)); alert.setCoordinates(parseGeoPoint); alert.setCreatedAt(new Date(Long.valueOf(dateCreatedAtList.get(i)))); alertsList.add(alert);        }    }    public GoogleMap.onMarkerClickListener getInfoMarkerClickListener() {        return new GoogleMap.onMarkerClickListener() { @Override public boolean onMarkerClick(Marker marker) {     alert alert = markerDataMap.get(marker);     busNumberTextView.setText(alert.getDescription());     descriptionTextView.setText(alert.getBusNumber());     alertTimeTextView.setText(dateCreatedAtList.get(alert.getId()));     marker.showInfoWindow();     return true; }        };    }}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/595860.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号