package com.example.maptest;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.Point;
import android.os.Bundle;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.Projection;
public class MainActivity extends MapActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
MapView mapView = (MapView) findViewById(R.id.map);
mapView.setClickable(true);
mapView.setBuiltInZoomControls(true);
TestOverlay overlay = new TestOverlay();
mapView.getOverlays().add(overlay);
MapController mc = mapView.getController();
mc.setZoom(21);
mapView.invalidate();
}
@Override
protected boolean isRouteDisplayed() {
return false;
}
static class TestOverlay extends Overlay {
private Point mPoint1, mPoint2
;
@Override
public void draw
(Canvas canvas, MapView mapView,
boolean shadow
) { super.draw(canvas, mapView, shadow);
if (!shadow) {
Projection pj = mapView.getProjection();
GeoPoint center1 = mapView.getMapCenter();
GeoPoint center2 = new GeoPoint(center1.getLatitudeE6(), center1.getLongitudeE6());
mPoint1 = pj.toPixels(center1, mPoint1);
mPoint2 = pj.toPixels(center2, mPoint2);
mPaint.
setStyle(Style.
FILL); mPaint.setColor(0xff0000ff);
canvas.drawCircle(mPoint1.x, mPoint1.y, 5, mPaint); // これはちゃんと中心になる
mPaint.setColor(0xff00ff00);
canvas.drawCircle(mPoint2.x, mPoint2.y, 5, mPaint); // スクロールしてるほどずれる
}
}
}
}