簡體   English   中英

Android Google Maps API v2某些標記未顯示

[英]Android Google Maps API v2 some Markers not showing

我正在嘗試在地圖上繪制標記,該標記將被刪除並在調用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);
}

TL; DR:我是個白痴。 如果發現異常,請檢查您在外部地圖服務上獲得的坐標。

在服務器上載/下載期間交換了緯度和經度。 將方法調用追溯到服務器下載步驟,就產生了所有正確的(看起來)緯度/經度方法調用。 查看Log可以得到外觀正確的緯度/經度值,但直到現在我才發現將這些值插入地圖服務中以檢查它們是否正確才使我大吃一驚。 由於myLocation是在本地獲取的,因此在無法正確獲取值的情況下,它以及0.0、0.0(或其他不正確的值)都可以正常工作。 在正確的范圍內生成了隨機值,因此它們也正確顯示。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM