Android Map Issue? - android

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?

Related

how to display pop up text showing address in google map of android

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.

Android Png overlay problems

public PNGOverlay(Bitmap original, GeoPoint topLeftGeoPoint, GeoPoint bottomRightGeoPoint) {
this.original = Bitmap.createScaledBitmap(original, original.getWidth(), original.getHeight(), true);
...
topGeoPoint = topLeftGeoPoint;
bottomGeoPoint = bottomRightGeoPoint;
}
#Override
public void draw(Canvas canvas, MapView mapView, boolean shadow) {
super.draw(canvas, mapView, false);
Projection projection = mapView.getProjection();
Point leftTop = new Point();
Point rightTop = new Point();
Point rightBottom = new Point();
Point leftBottom = new Point();
projection.toPixels(topGeoPoint, leftTop);
projection.toPixels(new GeoPoint(topGeoPoint.getLatitudeE6(), bottomGeoPoint.getLongitudeE6()), rightTop);
projection.toPixels(bottomGeoPoint, rightBottom);
projection.toPixels(new GeoPoint(bottomGeoPoint.getLatitudeE6(), topGeoPoint.getLongitudeE6()), leftBottom);
....
Paint paint = new Paint();
paint.setFilterBitmap(true);
paint.setAntiAlias(true);
canvas.drawBitmap(original, null, new Rect(leftTop.x, leftTop.y, rightBottom.x, rightBottom.y), paint);
....
}
I have a problem with this code. When I draw the png on the mapView, the png image is showed over the compass and over the GPS position indicatior? Any idea?
From your question is difficult to guess what is exactly your problem, but if you mean that the PNG is being drawn over the other overlays and you want it to be under them, you can solve it by adding the PNG overlay first to the mapview.
MapView calls the draw method from each overlay by the order that you add them:
mapview.getoverlays().add(overlay1);
mapview.getoverlays().add(overlay2);
This results in overlay2 being drawn over overlay1.
mapview.getoverlays().add(overlay2);
mapview.getoverlays().add(overlay1);
This results in overlay1 being drawn over overlay2.
good luck.

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

How to make Overlay to show above canvas.drawLine in Android map API

I have used the draw() method of my SitesOverlay class that is extending the ItemizedOverlay<OverlayItem> to draw some lines. Now, I am also putting in multiple images to the map as overlay by adding this one image to the List<OverlayItem> at many different points.
What happens now is that wherever the line (drawn using the draw() method) and the image icon overlap, the line is drawn over the overlayed image.
How do I make the overlay image come on top of the line?
Edit: I am using populate() to put all my overlays on the map, as soon as i add them to the list. IS there any way I can call populate after I have used my draw() method? I tried putting populate into the draw() method but the application stopped working...any other way?
Here I am sharing my source
public void draw(Canvas canvas, MapView mapView, boolean shadow) {
super.draw(canvas, mapView, shadow);
try {
for (int i = 0; i < size(); i++) {
OverlayItem item = getItem(i);
String driverName = item.getSnippet();
Data.activlyShownDrivers.add(driverName);
Point screenPts = new Point();
mapView.getProjection().toPixels(item.getPoint(), screenPts);
Bitmap bmp = null;
Context ctx = ShowAll.getContext();
long angle = (long) Double.parseDouble(item.getTitle());
// ---add the marker---
bmp = BitmapFactory.decodeResource(ctx.getResources(),
R.drawable.img1);
Paint paint = new Paint();
paint.setColor(Color.BLACK);
paint.setStyle(Style.FILL_AND_STROKE);
canvas.drawBitmap(bmp, screenPts.x, screenPts.y, null);
canvas.drawText(driverName, screenPts.x, screenPts.y, paint);
}
// }
} catch (Exception e) {
try {
Log.e(Data.LOG, e.getMessage());
} catch (Exception e1) {
e1.printStackTrace();
}
}
}
well, it figures that if you are using the draw method, then whatever you draw using it, will be drawn over your overlays. This is because draw() is called every time you drag/zoom or do anything with the map and overlays are populated only at the beginning...so drawn lines using draw() will always come over the overlays..

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