【问题标题】:Android Google Maps API v2 some Markers not showingAndroid Google Maps API v2 一些标记未显示
【发布时间】:2015-06-13 23:26:11
【问题描述】:

我正在尝试在地图上绘制标记,这些标记将在调用 updateMap() 时被移除并重新绘制,但某些标记并未被绘制。 Android Google Maps API v2 是否会阻止绘制彼此过于接近的标记?当它们是随机生成的并且日志显示正在解析正确的纬度/经度坐标时,绘制点没有问题,但是如果它的坐标太接近 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);
}

【问题讨论】:

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


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-01-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-16
      • 2014-07-29
      • 2014-01-15
      • 2012-04-12
      相关资源
      最近更新 更多