how to use two overlay in android map - android

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.

Related

how to draw root path when i am moving?

I am implementing an app using Google Maps. When the app comes into the foreground I am getting the current position lat,long and push pin on the map.
But I require that when I am moving, I want to draw a root path based on my movement.
If any one knows the solution, please help me.
Thanks in advance.
Have you tried to make a class which exends Overlay?
class MyOverlay extends Overlay{
public MyOverlay(){
}
public void draw(Canvas canvas, MapView mapv, boolean shadow){
super.draw(canvas, mapv, shadow);
Paint mPaint = new Paint();
mPaint.setDither(true);
mPaint.setColor(Color.RED);
mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
mPaint.setStrokeJoin(Paint.Join.ROUND);
mPaint.setStrokeCap(Paint.Cap.ROUND);
mPaint.setStrokeWidth(2);
GeoPoint gP1 = new GeoPoint(19240000,-99120000);
GeoPoint gP2 = new GeoPoint(37423157, -122085008);
Point p1 = new Point();
Point p2 = new Point();
Path path = new Path();
projection.toPixels(gP1, p1);
projection.toPixels(gP2, p2);
path.moveTo(p2.x, p2.y);
path.lineTo(p1.x,p1.y);
canvas.drawPath(path, mPaint);
}
Use it this way:
private List<Overlay> mapOverlays;
private Projection projection;
mapOverlays = mapView.getOverlays();
projection = mapView.getProjection();
mapOverlays.add(new MyOverlay());
Hope this helps!

Google Maps' marker moves when zooming

I've added a mark to my map but when I zoom in it moves to the left (at maximum zoom in it marks the right place) and when I zoom out it moves to the right (at maximum zoom out it marks like 3000Km from the right place).
Here's the class that draws the marker before the onCreate (the image is 62px w x 70px h):
class MapOverlay extends com.google.android.maps.Overlay
{
#Override
public boolean draw(Canvas canvas, MapView map, boolean shadow, long when)
{
super.draw(canvas, map, shadow);
Point screenPts = new Point();
map.getProjection().toPixels(point, screenPts);
Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.mapmarker);
canvas.drawBitmap(bmp, screenPts.x + 50, screenPts.y - 70, null);
return true;
}
}
And here's the code I use to call the class:
latitud = loc.getLatitude();
longitud = loc.getLongitude();
precision = loc.getAccuracy();
controlMapa = map.getController();
point = new GeoPoint((int) (latitud * 1E6), (int) (longitud * 1E6));
controlMapa.animateTo(point);
controlMapa.setZoom(17);
MapOverlay mapOverlay = new MapOverlay();
List<Overlay> listOfOverlays = map.getOverlays();
listOfOverlays.clear();
listOfOverlays.add(mapOverlay);
map.invalidate();
What's the problem? How can I make them move to the correct point each time zoom changes?
Thank you in advance!
Solved! I just had to add:
canvas.drawBitmap(bmp, screenPts.x - (bmp.getWidth() / 2), screenPts.y - bmp.getHeight(), new Paint());
instead of:
canvas.drawBitmap(bmp, screenPts.x + 50, screenPts.y - 70, null);

Rotating image in Google map in android

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;
}
}

Android Map Issue?

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?

adding multiple overlay items on google map

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.

Categories

Resources