可以“叠加"大小与android上的谷歌地图一起缩放? [英] Can "overlay" size be zoomed together with the google map on android?

查看:21
本文介绍了可以“叠加"大小与android上的谷歌地图一起缩放?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经能够使用MapActivity"和ItemizedOverlay"在带有 Eclipse 的 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?

我找不到定义边界的教程(例如,使用 GPS 坐标作为叠加图像的角).如果您知道一些,请提供链接.

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.

还有其他方法吗?

非常感谢.

推荐答案

是的,有.我的申请也有同样的问题.这是一个例子,它完美地工作.当您放大和缩小地图时,此处绘制的圆圈会按比例缩放.

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.

在你的 Overlay 类中:

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

当您的叠加层从缩放中重新绘制时,标记将根据 MeterToRadius 比例调整其大小.希望对您有所帮助.

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

这篇关于可以“叠加"大小与android上的谷歌地图一起缩放?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆