i want to mark with push pin image on more than one places on google map using overlayitem class..OR in simple how to add more than one overlay items on map..
as of now i can only mark a single place by overriding draw method of mapoverlay subclass...
here is my code
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, screenPts.y-24, null);
return true;
}
}
You can draw as many things as you like in the draw() method so just iterate over all the points you have in a loop and draw them one by one.
Related
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);
Point screenPts = new Point();
// scree.openInfoWindowHtml("Hello, World!" );
mapView.getProjection().toPixels(g, screenPts);
Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.flag);
canvas.drawBitmap(bmp, screenPts.x, screenPts.y-50, null);
//TextView bubble=
return true;
}
}
Maybe you should check this: https://github.com/jgilfelt/android-mapviewballoons
It's really good and easy to use, much faster than rolling your own. If you want to learn you can always study the source.
I need two overlay item in the map.I have used the following code to get the overlay
enter code here 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);
Paint paint = new Paint();
//---translate the GeoPoint to screen pixels---
Point screenPts = new Point();
mapView.getProjection().toPixels(p, screenPts);
// mapView.getProjection().toPixels(p1, screenPts);
paint.setStrokeWidth(1);
paint.setARGB(255, 255, 00, 00);
paint.setStyle(Paint.Style.STROKE);
//---add the marker---
Bitmap bmp = BitmapFactory.decodeResource(
getResources(), R.drawable.marker);
canvas.drawBitmap(bmp, screenPts.x, screenPts.y, paint);
canvas.drawText("Here I am...", screenPts.x, screenPts.y, paint);
return true;
}
MapOverlay mapOverlay = new MapOverlay();
List<Overlay> listOfOverlays = mapView.getOverlays();
listOfOverlays.clear();
listOfOverlays.add(mapOverlay);
mapView.invalidate();
the below code in in on create portion.from this code i could only get one overlay .how can I use it to get another overlay?I want two overlay,how could I get another one from this code?
You can use two/multiple overlay by adding MapOverlay on List<Overlay> as listOfOverlays.add(mapOverlay);. To know more information about adding Map overlay in android map, look at the answer Here
You just need to repeat the line:
listOfOverlays.add(mapOverlay);
everytime you want to add another overlay to mapview.
I using Google map in my android application,I am facing a problem in Google map,I want to rotate image in Google map relative to GeoPoint in Google map.
Just like this.
click here.
Your help will deeply appreciated.
Regards
Altaf
Extend the MapOverlay class. Override the draw() method and draw what is needed. Look for other answers on stackoverflow to draw a rotated bitmap to canvas within the draw method. code snippet to get you started:
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(carloc, screenPts);
//---add the marker---
Bitmap bmp = BitmapFactory.decodeResource(
getResources(), R.drawable.marker);
canvas.drawBitmap(bmp, screenPts.x, screenPts.y-50, null);
return true;
}
}
To show an specific location in android Map, I am using overlay class, and paint object which have reference of Geo point, drawing an balloon bitmap image.
But when I zoom (in/out) map, my balloon does not adjust according to the changed view of the map.
I'm using the following overlay pattern:
class MapOverlay extends com.google.android.maps.Overlay
{
#Override
public void draw(Canvas canvas, MapView mapView, boolean shadow) {
Point point = null, point1 = null;
if(p!=null)
{
point = new Point();
mapView.getProjection().toPixels(p, point);
Bitmap bmp = BitmapFactory.decodeResource(
getResources(), R.drawable.redbaloon);
canvas.drawBitmap(bmp, point.x-38, point.y+60, null);
}}
How can I draw balloon with zooming?
I'm trying to add text labels next to my overlay images. So far the only way I can see to do this would be to use the draw method and draw the text as overlay. I did this, but somehow it isn't showing me the drawn text. My code looks like:
SitesOverlay that extends ItemizedOverlay<OverlayItem>
public void draw(Canvas canvas, MapView mapView,boolean shadow) {
int i;
Paint paint=new Paint();
paint.setStrokeWidth(1);
paint.setARGB(255, 255, 255, 255);
paint.setStyle(Paint.Style.STROKE);
super.draw(canvas, mapView, shadow);
boundCenterBottom(station);
canvas.drawText("hullo",28632877,77219722, paint);
}
My constructor in the SitesOverlay class just adds the images to many different GeoPoints.
Now, in my OnCreate I have this piece of code:
map.getOverlays().add(new SitesOverlay(station));
This is adding the list of images in my constructor - SitesOverlay(station) as overlays.
My question is that since I have added my text in the Draw method of the SitesOverlay class and not in this constructor, is this why the text is not being drawn on the map? If so how do I add the text to the map?
Do the things drawn in the draw() method automatically get added as an overlay? Coz i think thats what is causing the problem here...
Any other way I can add text labels next to my overlay images?
Plz help...
try this..
MyLocationOverlay myTouchOverlay = new MyLocationOverlay ();
List<Overlay> list1 = myMapView.getOverlays();
list1.add(myTouchOverlay);
class MyLocationOverlay extends com.google.android.maps.Overlay {
#Override
public boolean onTap(GeoPoint p, MapView mapView) {
}
#Override
public boolean draw(Canvas canvas, MapView mapView, boolean shadow,
long when) {
super.draw(canvas, mapView, shadow);
Paint paint = new Paint();
// Converts lat/lng-Point to OUR coordinates on the screen.
Point myScreenCoords = new Point();
mapView.getProjection().toPixels(point, myScreenCoords);
paint.setStrokeWidth(1);
paint.setARGB(255, 255, 255, 255);
paint.setStyle(Paint.Style.STROKE);
paint.setTextSize(20);
paint.setColor(Color.RED);
paint.setStrokeWidth(2);
canvas.drawText("Here I am...", myScreenCoords.x-10,myScreenCoords.y-48, paint);
return true;
}
}