Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can "overlay" size be zoomed together with the google map on android?

I have been able to use "MapActivity" and "ItemizedOverlay" to draw overlays on google maps on android with Eclipse. But when the map is zooming in and out, the overlay does not change size.

I want the overlay to be "fixed" on the map, and zoom in and out along with the map. How can this be done?

I can't find the tutorial to define a boundary (e.g. with GPS coordinates as corners for the overlay image). Please provide links if you know some.

and any other ways of doing it?

Many thanks.

like image 713
lionfly Avatar asked Jul 06 '11 15:07

lionfly


People also ask

Can you use Google Maps and zoom at the same time?

Google Maps - cannot zoom and move at the same time with animateCamera, but can with moveCamera. Bookmark this question.

Can you put overlays on Google Maps?

Use map images to create extra information without embedding it into your original map. To see how an overlay image corresponds to the map image underneath it: Select the overlay in the viewer. Then, change the transparency so that it's fully opaque.

How do I custom zoom on Google Maps?

You can change the zoom level of the map using simple steps. Step 1 Go to Add or Edit Map page . Step 2 Select 'Default zoom level' in the 'Map Information section'. Step 3 click save map and see the changes.

How do I control zoom on Google Maps?

Users can zoom the map by clicking the zoom controls. They can also zoom and pan by using two-finger movements on the map for touchscreen devices.


1 Answers

Yes, there is. I had the same issue with my application. Here's an example and it works perfectly. The circle drawn here scales as you zoom in and out of the map.

In your Overlay class:

public class ImpactOverlay extends Overlay {

private static int CIRCLERADIUS = 0;
private GeoPoint geopoint;

public ImpactOverlay(GeoPoint point, int myRadius) {
    geopoint = point;
    CIRCLERADIUS = myRadius;
}

@Override
public void draw(Canvas canvas, MapView mapView, boolean shadow) {
    // Transfrom geoposition to Point on canvas
    Projection projection = mapView.getProjection();
    Point point = new Point();
    projection.toPixels(geopoint, point);

    // the circle to mark the spot
    Paint circle = new Paint();
    circle.setColor(Color.BLACK);
    int myCircleRadius = metersToRadius(CIRCLERADIUS, mapView, (double)geopoint.getLatitudeE6()/1000000);
    canvas.drawCircle(point.x, point.y, myCircleRadius, circle);
}

public static int metersToRadius(float meters, MapView map, double latitude) {
    return (int) (map.getProjection().metersToEquatorPixels(meters) * (1/ Math.cos(Math.toRadians(latitude))));         
}
}

As your overlay re-draws from zoom, the marker will resize with it based on the metersToRadius scale. Hope it helps.

like image 73
Jacob Robinson Avatar answered Nov 11 '22 14:11

Jacob Robinson