Reputation: 385
Hi every body iam working with an Android application which contains a Google Map with hundreds of Markers.Here iam able to show all the Markers on the Map.But here my requirement is i have to show only first five markers in the google map with the max zoom level.It is exemption to the markers whose latitude and longitude falls in between the current showing five markers.This requirement is because if there are thousands of markers the map becomes cloudy.Below is my code.
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;
}
Any suggestions are greatly appreciated.
Thanks&Regards,
Venkat
Upvotes: 0
Views: 280
Reputation: 34301
Change this with
for(int pinret=0;pinret<mpDt.size();pinret++){
}
this,
int size = mpDt.size();
if(size > 5)
size =5 ;
for(int pinret=0;pinret<size;pinret++){
}
Upvotes: 0
Reputation: 1593
There is a difference between just drawing the first five, and only adding the first 5. I dont know about only drawing the first five, but to only add 5, couldnt you change pinret < mpDt.size()
to pinret < 5
? Obviously, this could cause problems if mpDt contains less than 5 items so youll need to do some bounds checking
Upvotes: 1