无法在地图上看到之前添加的标记

时间:2017-01-27 03:10:01

标签: android google-maps google-maps-api-3 google-maps-markers google-maps-android-api-2

我正在开发此应用,其中用户收集相同的活动,并且在该活动中有Map,一旦添加用户就会更新并在地图上显示他/她的位置。我有一个列表,其中添加了打开此活动的用户,并且我正在使用其适配器的getAdapterItemCount()属性来实现我的逻辑。

这就是我正在做的事情:

                mMap.setOnMapLoadedCallback(new GoogleMap.OnMapLoadedCallback() {
                    @Override
                    public void onMapLoaded() {
                        //animate camera here

                        if (aFastItemAdapter.getAdapterItemCount() > 0 && aFastItemAdapter.getAdapterItemCount() == 1 && aFastItemAdapter.getAdapterItemCount() < 2) {
     pMarker = mMap.addMarker(new MarkerOptions().position(new LatLng(currentLtAU, currentLnAU)).title(pWhoAccepted.trim()));
     markersList.add(pMarker);
} else if (aFastItemAdapter.getAdapterItemCount() > 1 && aFastItemAdapter.getAdapterItemCount() == 2 && aFastItemAdapter.getAdapterItemCount() < 3) {
     sPlayerMarker = mMap.addMarker(new MarkerOptions().position(new LatLng(currentLtAU, currentLnAU)).title(pWhoAccepted.trim()));
     markersList.add(sPlayerMarker);
} else if (aFastItemAdapter.getAdapterItemCount() > 2 && aFastItemAdapter.getAdapterItemCount() == 3 && aFastItemAdapter.getAdapterItemCount() < 4) {
     tPlayerMarker = mMap.addMarker(new MarkerOptions().position(new LatLng(currentLtAU, currentLnAU)).title(pWhoAccepted.trim()));
     markersList.add(tPlayerMarker);
} else if (aFastItemAdapter.getAdapterItemCount() > 3 && aFastItemAdapter.getAdapterItemCount() == 4 && aFastItemAdapter.getAdapterItemCount() < 5) {
     fPlayerMarker = mMap.addMarker(new MarkerOptions().position(new LatLng(currentLtAU, currentLnAU)).title(pWhoAccepted.trim()));
     markersList.add(fPlayerMarker);
} else if (aFastItemAdapter.getAdapterItemCount() > 4 && aFastItemAdapter.getAdapterItemCount() == 5 && aFastItemAdapter.getAdapterItemCount() < 6) {
     faPlayerMarker = mMap.addMarker(new MarkerOptions().position(new LatLng(currentLtAU, currentLnAU)).title(pWhoAccepted.trim()));
     markersList.add(faPlayerMarker);
} else if (aFastItemAdapter.getAdapterItemCount() > 5 && aFastItemAdapter.getAdapterItemCount() == 6 && aFastItemAdapter.getAdapterItemCount() < 7) {
     saPlayerMarker = mMap.addMarker(new MarkerOptions().position(new LatLng(currentLtAU, currentLnAU)).title(pWhoAccepted.trim()));
     markersList.add(saPlayerMarker);
}

                        ////get the latLngbuilder from the marker list
                        LatLngBounds.Builder builder = new LatLngBounds.Builder();
                        for (Marker m : markersList) {
                            builder.include(m.getPosition());
                        }

                        //Bounds padding here
                        int padding = 100;

                        //Create bounds here
                        LatLngBounds bounds = builder.build();

                        //Create camera with bounds
                        final CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, padding);

                        mMap.animateCamera(cu);

                        mMap.getUiSettings().setZoomControlsEnabled(true);
                        mMap.getUiSettings().setMapToolbarEnabled(true);
                        mMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
                        mMap.setMaxZoomPreference(19.0f);

                    }
                });

问题,假设地图上已经有marker,我是第二个被添加的人,所以在我之前添加的用户可以看到我的标记地图但是,我无法看到他的。

我的代码出了什么问题?我怎么能让每个用户都能看到地图上可用的所有标记,无论它们是在第一个位置还是在任何位置添加它们?

0 个答案:

没有答案