Try this.....it worked for me...download a "pushpin" image and put it in ur
drawable folder.
Look at the highlighted code.
public class GoogleMap extends MapActivity {
class MapOverlay extends com.google.android.maps.Overlay
{
@Override
public boolean draw(Canvas canvas, MapView mapView,
boolean shadow, long when)
{
super.draw(canvas, mapView, shadow);
//---translate the GeoPoint to screen pixels---
Point screenPts = new Point();
mapView.getProjection().toPixels(p, screenPts);
* //---add the marker---
Bitmap bmp = BitmapFactory.decodeResource(
getResources(), R.drawable.pushpin);
canvas.drawBitmap(bmp, screenPts.x+5, screenPts.y-60,
null);
return true;
}*
}
private MapView mapView;
private MapController mc;
private GeoPoint p;
String caption = null;
String Latitude = null;
String Longitude = null;
String id = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
try{
setContentView(R.layout.YOUR LAYOUT);
Intent i = getIntent();
Latitude = i.getStringExtra("Latitude");
Longitude = i.getStringExtra("Longitude");
mapView = (MapView) findViewById(R.id.YOUR MAPVIEW ID);
mapView.setBuiltInZoomControls(true);
mapView.postInvalidate();
mc = mapView.getController();
double lat = Double.parseDouble(Latitude);
double lng = Double.parseDouble(Longitude);
p = new GeoPoint(
(int) (lat * 1E6),
(int) (lng * 1E6));
mc.animateTo(p);
mc.setZoom(17);
* //---Add a location marker---
MapOverlay mapOverlay = new MapOverlay();
List<Overlay> listOfOverlays = mapView.getOverlays();
listOfOverlays.clear();
listOfOverlays.add(mapOverlay);
mapView.invalidate();
*
}catch (Exception e) {
///////.............your code...........//////////
}
});
}
}
private Bitmap getBitmapFromAsset(String strName) throws IOException
{
AssetManager assetManager = getAssets();
InputStream istr = assetManager.open(strName);
Bitmap bitmap = BitmapFactory.decodeStream(istr);
return bitmap;
}
/**
* Instructs the map view to navigate to the point and zoom level
specified.
* @param geoPoint
* @param zoomLevel
*/
@Override
protected boolean isRouteDisplayed() {
return false;
}
}
HOPE THIS HELPS.
On Mon, Jun 27, 2011 at 3:56 PM, Ishwar Chawla <[email protected]>wrote:
> I want to show some markers on my map on emulator.I am able to load
> map but I dont see marker I have tried so many things available on net
> but I just cant get done.Any Help.
>
> My Customized class
> import java.util.ArrayList;
> import android.content.Context;
> import android.graphics.drawable.Drawable;
> import com.google.android.maps.ItemizedOverlay;
> import com.google.android.maps.OverlayItem;
>
> public class CustomItemizedOverlay extends
> ItemizedOverlay<OverlayItem>{
>
> private ArrayList<OverlayItem> mOverlays=new
> ArrayList<OverlayItem>();
> Context mContext;
>
> public CustomItemizedOverlay(Drawable defaultMarker) {
> super(defaultMarker);
> }
>
> public CustomItemizedOverlay(Drawable defaultMarker,Context context)
> {
> super(defaultMarker);
> mContext = context;
> }
> public void addOverlay(OverlayItem overlay) {
> mOverlays.add(overlay);
> populate();
> }
>
> @Override
> protected OverlayItem createItem(int i) {
> return mOverlays.get(i);
> }
>
> @Override
> public int size() {
> return mOverlays.size();
> }
> }
>
> Snippet of code on create.
>
> mapOverlays = mapView.getOverlays();
> Drawable drawable =
> this.getResources().getDrawable(R.drawable.pinkmarker);
> CustomItemizedOverlay itemizedoverlay = new
> CustomItemizedOverlay(drawable);
> GeoPoint g=new GeoPoint(lat,lon);
> OverlayItem i=new OverlayItem(g,info,info);
> OverlayItem h=new OverlayItem(new
> GeoPoint(12912834,77609225),info,info);
> itemizedoverlay.addOverlay(i);
> itemizedoverlay.addOverlay(h);
> mapController.animateTo(g);
> mapOverlays.add(itemizedoverlay);
> mapView.postInvalidate();
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
--
Regards,
Arpit Hada
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en