我试图在地图上绘制标记,这些标记将被移除并在调用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);
}
答案 0 :(得分:1)
TL; DR:我是个白痴。如果您得到异常结果,请检查您在外部地图服务上获得的坐标。
在服务器上传/下载期间交换纬度和经度。跟踪方法回调到服务器下载步骤,产生了所有正确的(纵向)纬度/经度方法调用。查看日志会产生正确的纬度/经度值,但直到现在才将其插入地图服务中以检查它们是否准确。由于myLocation是在本地获得的,所以它的工作正常,以及0.0,0.0(或其他不正确的值),因为没有正确获取值。在正确的范围内生成随机值,因此它们也正确显示。