Android Google Maps API v2 some Markers not showing

482 views Asked by At

I'm trying to draw markers on the map which will be removed and redrawn as updateMap() is called, but some markers are not being drawn. Does the Android Google Maps API v2 prevent drawing markers that are too close to one another? It has no problem drawing the points when they're randomly generated and the log shows the correct Lat/Lon coordinates are being parsed, but it won't draw the marker if its coordinates are too close to myMarker (the threshold of which I don't know exactly, but for the purposes of the app, it's too large).

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);
}
1

There are 1 answers

0
bhellis On BEST ANSWER

TL;DR : I'm an idiot. Check the coordinates you're getting on an outside map service if you get anomalous results.

Latitude and Longitude were being swapped during server upload/download. Tracing the method calls back to the server download step yielded all the correct(-looking) latitude/longitude method calls. Looking at the Log yielded correct-looking latitude/longitude values, but it didn't strike me until now to plug those into a map service to check if they were accurate. Since myLocation was being acquired locally, it worked fine, as well as 0.0, 0.0 (or other incorrect values) for when a value wasn't being being acquired properly. Random values were generated within the correct ranges, so they appeared properly as well.