Android Google 地图 API v2 一些标记未显示

Android Google Maps API v2 some Markers not showing

我正在尝试在地图上绘制标记,这些标记将在调用 updateMap() 时被移除并重新绘制,但有些标记没有被绘制。 Android Google Maps API v2 是否可以防止绘图标记彼此靠得太近?当它们随机生成并且日志显示正在解析正确的 Lat/Lon 坐标时绘制点没有问题,但如果它的坐标太接近 myMarker (其阈值我不太清楚,但就应用程序而言,它太大了)。

public void updateMap() {
    if (myMarker != null)
        myMarker.remove();
    for (Marker m : friendMarkers)
        m.remove();

    myLocation = new LatLng(((MainPageActivity) getActivity()).getLatitude(),
                            ((MainPageActivity) getActivity()).getLongitude());

    myMarker = map.addMarker(new MarkerOptions().position(  myLocation) // Marker is set at my location
                                                                        // Title of Marker is set to user-determined value
                                                .title( ((MainPageActivity) getActivity()).getUsername() + " : You Are Here").visible(true)
                                                .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE)));

    // DEBUG - To be commented/removed
    Toast.makeText( getActivity().getApplicationContext(),
                    "UPDATING MAP\nshowFriendList size: " + ((MainPageActivity) getActivity()).showFriendList.size(), Toast.LENGTH_SHORT)
            .show();

    Log.d("Drawing Friends on Map", "Number of Friends: " + ((MainPageActivity)getActivity()).showFriendList.size());
    Log.d("Drawing Friends on Map", "Number of Friends Total: " + ((MainPageActivity)getActivity()).allFriendList.size());


    double friendLat, friendLon;

    // Loop through currently selected Friends list (showFriendList)
    for (Friend friend : ((MainPageActivity) getActivity()).showFriendList) {


        // THe user is also in the showFriendList, but we don't need to draw them
        if (!friend.getID().equals(((MainPageActivity)getActivity()).userId)){


        // Random rng = new Random();
        // friendLat = ((rng.nextInt() % 180000000) - 90000000) / 1000000.0; // Range +/- 90.0
        // friendLon = ((rng.nextInt() % 360000000) - 180000000) / 1000000.0; // Range +/- 180.0

        friendLat = ((MainPageActivity)getActivity()).getFriendLatitudeFromAll(friend);
        friendLon = ((MainPageActivity)getActivity()).getFriendLongitudeFromAll(friend);
        //friendLocation = new LatLng(friendLat, friendLon);

            Bitmap bmp = ig.makeIcon(friend.getName());

            // Make a LatLng item with the appropriate location
            Log.e("Drawing Friends","Drawing Friend : "+friend.getName()+" at Lat: " + friendLat + " Lon: " + friendLon);

            Marker toAdd = map.addMarker(new MarkerOptions()
                .position(new LatLng(friendLat, friendLon))
                .title(friend.getName()).visible(true)
                //.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE))
                .icon(BitmapDescriptorFactory.fromBitmap(bmp))
                );

            friendMarkers.add(toAdd);

            Log.d("Drawing Friend on Map", "Friend: " + friend.getName() + " Location: Lat: " + friend.getLatitude() + " Lon: " + friend.getLongitude());
        }
    }

    // Disable map's buttons for external apps
    map.getUiSettings().setMapToolbarEnabled(false);
}

TL;DR:我是个白痴。如果您得到异常结果,请检查您在外部地图服务上获得的坐标。

在服务器 upload/download 期间交换纬度和经度。将方法调用追溯到服务器下载步骤产生了所有正确的(看起来)latitude/longitude 方法调用。查看日志会产生看起来正确的 latitude/longitude 值,但直到现在我才想到将它们插入地图服务以检查它们是否准确。由于 myLocation 是在本地获取的,因此它工作正常,并且在未正确获取值时为 0.0、0.0(或其他不正确的值)。随机值是在正确的范围内生成的,因此它们也能正确显示。