Android的谷歌地图groundoverlay [英] Android google maps groundoverlay
问题描述
在谷歌地图的JavaScript API,你可以添加一个groundoverlay,只是传递两个点,该点lefttoplat和放大器; lefttoplong和点rightbottomlat和放大器; rightbottomlong ......(正常覆盖不这两个点之间留下,但留下来的当你放大或缩小尺寸相同。)
In the google maps javascript api you can add a groundoverlay and just pass two points, the point lefttoplat&lefttoplong and the point rightbottomlat&rightbottomlong... (The normal overlays don't stay between these two points, but stay the same size when you zoom in or out.)
我一直在寻找类似的东西在Android谷歌地图的API,但我找不到它的任何地方。有没有在Android地图API这样的事情,如果有没有,什么是模拟这种功能的最佳方法是什么?
I have been searching for something like that in the Android google maps api, but I can't find it anywhere. Is there such a thing in the android maps api and if there's not, what's the best way to simulate this function?
推荐答案
这是更好的。使用拉伸方法可以确保只绘制位图,实际上是在屏幕上的一部分。我仍然获得了超过VM-预算错误的时候。我仍然在寻找到这一点。
This is better. Using the draw-method makes sure you only draw the part of the bitmap that is actually on the screen. I still get the exceeded VM-budget error sometimes. I'm still looking into that.
public class GroundOverlay extends Overlay {
Bitmap original;
Bitmap resized;
int lastZoomlevel;
SnowmapsOverlayObject snowmapsObject;
public static Boolean DRAW = false;
GeoPoint topGeoPoint;
GeoPoint bottomGeoPoint;
OnReady _onReady = null;
Boolean ready = false;
public GroundOverlay(Bitmap original, SnowmapsOverlayObject snowmapsObject) {
this.original = Bitmap.createScaledBitmap(original, original.getWidth(), original.getHeight(), true);
this.snowmapsObject = snowmapsObject;
topGeoPoint = new GeoPoint((int) ((snowmapsObject.topLat).doubleValue() * 1E6), (int) ((snowmapsObject.topLng).doubleValue() * 1E6));
bottomGeoPoint = new GeoPoint((int) ((snowmapsObject.bottomLat).doubleValue() * 1E6), (int) ((snowmapsObject.bottomLng).doubleValue() * 1E6));
}
@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);
if (
(leftTop.x < 0 || leftTop.y < 0) &&
(rightTop.x < 0 || rightTop.y < 0) &&
(rightBottom.x < 0 || rightBottom.y < 0) &&
(leftBottom.x < 0 || leftBottom.y < 0)) {
// Not on screen? Don't draw the overlay
return;
}
// GeoPoint mapCenter = mapView.getMapCenter();
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);
if (!ready && _onReady != null) {
ready = true;
_onReady.done();
}
}
@Override
public boolean onTouchEvent(MotionEvent e, MapView mapView) {
super.onTouchEvent(e, mapView);
if (e.getAction() == MotionEvent.ACTION_UP) {
setDrawTrue();
}
return false;
}
private void setDrawTrue() {
DRAW = true;
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
DRAW = false;
}
}, 100);
}
public void setOnReady(OnReady onReady) {
this._onReady = onReady;
}
public interface OnReady {
public void done();
}
}
这篇关于Android的谷歌地图groundoverlay的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!