Can quot;overlayquot; size be zoomed together with the google map on android?(可以“叠加大小与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上的谷歌地图一起缩放?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:可以“叠加"大小与android上的谷歌地图一起缩放?
基础教程推荐
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01