[android-developers] Adding markers with different drawables on google map in android
Hi,
I am trying to plot some markers on a google map.There are 2 different marker drawables, the orange one is for the user's location and green ones are for all other points.I have followed this source code from CommonsWare.Here is my ItemizedOverlay and OverlayItem class:
class DoItemizedOverlay extends ItemizedOverlay<CustomOverlayItem> {
private ArrayList<CustomOverlayItem> items = new ArrayList<CustomOverlayItem>();
Context mcontext;
public DoItemizedOverlay(Context context,ArrayList<OverlayPoint> overlays)
{
super(null);
mcontext=context;
// TODO Auto-generated constructor stub
for(OverlayPoint p:overlays)
{
CustomOverlayItem item;
if(p.src)
{
item=new CustomOverlayItem(p.p,p.name, p.snippet, getMarker(R.drawable.src_marker), true);
}
else
{
item=new CustomOverlayItem(p.p, p.name, p.snippet, getMarker(R.drawable.marker), false);
}
items.add(item);
//populate();
}
Log.d("MAPI", String.valueOf(items.size()));
populate();
}
@Override
public void draw(Canvas canvas, MapView mapView,
boolean shadow) {
super.draw(canvas, mapView, false);
}
@Override
protected CustomOverlayItem createItem(int i)
{
return items.get(i);
}
@Override
public int size()
{
return items.size();
}
private Drawable getMarker(int resource) {
Drawable marker=getResources().getDrawable(resource);
marker.setBounds(0, 0, marker.getIntrinsicWidth(),
marker.getIntrinsicHeight());
boundCenter(marker);
return(marker);
}
}
class CustomOverlayItem extends OverlayItem {
Drawable marker=null;
boolean src;
CustomOverlayItem(GeoPoint pt, String name, String snippet,
Drawable marker,boolean s) {
super(pt, name, snippet);
this.marker=marker;
this.src=s;
}
@Override
public Drawable getMarker(int stateBitset) {
setState(this.marker, stateBitset);
return(this.marker);
}
}
class OverlayPoint{
GeoPoint p;
String name,snippet;
boolean src;
public OverlayPoint(GeoPoint pn,String nm,String sn,boolean s) {
// TODO Auto-generated constructor stub
p=pn;
name=nm;
snippet=sn;
src=s;
}
}
DoItemizedOverlay sourcemarker=new DoItemizedOverlay(ChildcareHost.mContext,OPs);
mapView.getOverlays().add(sourcemarker);
mapView.setBuiltInZoomControls(true);
mapView.setStreetView(true);
mapView.invalidate();
mapView.getController().zoomToSpan(sourcemarker.getLatSpanE6(), sourcemarker.getLonSpanE6());
mapView.getController().animateTo(src);
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home