大家好,我正在使用一个 Android 应用程序,该应用程序包含一个带有数百个标记的谷歌地图。这里我能够在地图上显示所有标记。但我的要求是我必须在谷歌地图中只显示前五个标记最大缩放级别。对于经纬度在当前显示的五个标记之间的标记是豁免的。这个要求是因为如果有数千个标记,地图就会变得多云。下面是我的代码。
public void displayMapView(final Vector<MapData> retVector){
mapOverlays=mapView.getOverlays();
Drawable marker = getResources().getDrawable(R.drawable.map_pin);
marker.setBounds((int) (-marker.getIntrinsicWidth() / 2),-marker.getIntrinsicHeight(),(int) (marker.getIntrinsicWidth() / 2), 0);
funPlaces = new MyItemizedOverlay(marker,mapView);
mapView.getOverlays().add(funPlaces);
GeoPoint pt = funPlaces.getCenterPt();
int latSpan=funPlaces.getLatSpanE6();
int longSpan=funPlaces.getLonSpanE6();
mc=mapView.getController();
mc.setCenter(pt);
mc.zoomToSpan((int)(latSpan*1.5),(int)(longSpan*1.5));
//mc.zoomToSpan((int)(minLatitude-maxLatitude),(int)(minLatitude-maxLatitude));
}
@Override
protected boolean isLocationDisplayed(){
return false;
}
@Override
protected boolean isRouteDisplayed(){
return false;
}
public class MyItemizedOverlay extends BalloonItemizedOverlay<OverlayItem> {
private ArrayList<OverlayItem> m_overlays = new ArrayList<OverlayItem>();
@SuppressWarnings("unused")
private Context c;
private GeoPoint center = null;
public MyItemizedOverlay(Drawable marker,MapView mapView){
super(boundCenter(marker),mapView);
c = mapView.getContext();
try{
String name="",cusine="",distance="",price="",popUpDataNew="";
for(int pinret=0;pinret<mpDt.size();pinret++){
MapData retMapData=(MapData)mpDt.get(pinret);
resId=retMapData.getId();
name=retMapData.getName();
cusine=retMapData.getCusine();
distance=retMapData.getDistance();
price=retMapData.getPrice();
popUpDataNew=name+"/"+cusine+"/"+distance+"/"+price;
try{
double lat=Double.parseDouble(retMapData.getLatitude());
double lon=Double.parseDouble(retMapData.getLongitude());
GeoPoint pointNew= new GeoPoint((int)(lat*1E6),(int)(lon*1E6));
m_overlays.add(new OverlayItem(pointNew,popUpDataNew,resId));
populate();
}catch(NumberFormatException nfe){
nfe.printStackTrace();
}
}
}catch(Exception e){
e.printStackTrace();
}
}
public GeoPoint getCenterPt(){
if(center == null){
int northEdge = -90000000;
int southEdge = 90000000;
int eastEdge = -180000000;
int westEdge = 180000000;
Iterator<OverlayItem> iter = m_overlays.iterator();
while(iter.hasNext()){
GeoPoint pt = iter.next().getPoint();
if(pt.getLatitudeE6() > northEdge)
northEdge = pt.getLatitudeE6();
if(pt.getLatitudeE6() < southEdge)
southEdge = pt.getLatitudeE6();
if(pt.getLongitudeE6() > eastEdge)
eastEdge = pt.getLongitudeE6();
if(pt.getLongitudeE6() < westEdge)
westEdge = pt.getLongitudeE6();
}
center = new GeoPoint((int) ((northEdge + southEdge) / 2),(int) ((westEdge + eastEdge) / 2));
}
return center;
}
非常感谢任何建议。
感谢和问候,
文卡特