使用自定义标记映射+查看所有标记

时间:2014-01-18 10:05:52

标签: android

大家好我揭露了我的问题,但在我向您展示我创建的代码之前,为了更详细地介绍:

        @Override
    public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState, R.layout.activity_map);

            GoogleMap map = ((SupportMapFragment) getSupportFragmentManager()
                            .findFragmentById(R.id.map)).getMap();

            if (map != null) {
                    // Ciclo un mio ArrayList contenente contenuti con relative Latitudine e Longitudine
                    for (int i = 0; i < Contenuti.size(); i++) {
                            double lat = Double.parseDouble(Contenuti.get(i)
                                            .getLatitude());
                            double lng = Double.parseDouble(Contenuti.get(i)
                                            .getLongitude());

                            LatLng PUNTI = new LatLng(lat, lng);
                            String title = Contenuti.get(i).getName();

                            map.addMarker(new MarkerOptions()
                                            .position(POI_POINT).title(title));
                    }

                    map.moveCamera(CameraUpdateFactory.newLatLngZoom(STARTING_POINT, 5));
                    map.animateCamera(CameraUpdateFactory.zoomTo(15), 2000, null);

            }

    }

我认为到目前为止一切都很清楚:

1 - 加载地图;

2 - 使用所有conenuti循环一个ArrayList,并为每个内容关联一个标记。

那么请来我的要求或问题:

1 - 我应该在将所有标记放在地图上后,您可以在屏幕上看到显示所有标记的地图,我看到我的情况有一个方法“newLatLngBounds”谷歌地图中心/显示所有点并在屏幕上显示它们,但我不明白如何将它集成到我的代码中,或者更确切地说是我使应用程序必须出错的证据!

2 - 第二个问题是我应该以静态的方式将Marker图标的属性与从我的ArrayList中恢复的图像(在这种情况下是包含此图像的url)相关联......但这不是全部因为图像叠加或包含在我的pin.png中 - >在这种情况下,我已经看到使用'“InfoWindowAdapter”,但它不是我想要的!因为后者在我的自定义布局中创建了包含标记信息的屏幕,为了更好地传达我向您展示我尝试的代码的想法:

private class CustomInfoWindowAdapter implements InfoWindowAdapter {

            private View view;

            public CustomInfoWindowAdapter() {
                    view = getLayoutInflater().inflate(R.layout.custom_pin, null);
            }

            @Override
            public View getInfoContents(Marker marker) {
                    if (MapActivity.this.marker != null
                                    && MapActivity.this.marker.isInfoWindowShown()) {
                            MapActivity.this.marker.hideInfoWindow();
                            MapActivity.this.marker.showInfoWindow();
                    }
                    return null;
            }

            @Override
            public View getInfoWindow(final Marker marker) {
                    MapActivity.this.marker = marker;

                    String url = null;

                    if (marker.getId() != null && markers != null && markers.size() > 0) {
                            if (markers.get(marker.getId()) != null
                                            && markers.get(marker.getId()) != null) {
                                    url = markers.get(marker.getId());
                            }
                    }

                    final ImageView image = ((ImageView) view.findViewById(R.id.badge));

                    if (url != null && !url.equalsIgnoreCase("null")
                                    && !url.equalsIgnoreCase("")) {
                            ImageLoader.getInstance().displayImage(url, image);
                    } else {
                            image.setImageResource(R.drawable.ic_launcher);
                    }

                    return view;
            }

    }

    private void initWidget() {
            txtHeader = (TextView) findViewById(id.txtHeaderMenu);

            if (Commons.categoriesList != null) {
                    txtHeader.setText(Commons.categoriesList.get(Commons.cat_id)
                                    .getName());
            }

    }

我使用外部库universalimageloader来显示图像。它有效...但它不是我想要的,因为它们是应该采取这种效果的标记。

提前感谢您的合作

我等待你的建议......

0 个答案:

没有答案
相关问题