fork download
  1. package com.example.maptest;
  2.  
  3. import android.graphics.Canvas;
  4. import android.graphics.Paint;
  5. import android.graphics.Paint.Style;
  6. import android.graphics.Point;
  7. import android.os.Bundle;
  8.  
  9. import com.google.android.maps.GeoPoint;
  10. import com.google.android.maps.MapActivity;
  11. import com.google.android.maps.MapController;
  12. import com.google.android.maps.MapView;
  13. import com.google.android.maps.Overlay;
  14. import com.google.android.maps.Projection;
  15.  
  16. public class MainActivity extends MapActivity {
  17.  
  18. @Override
  19. public void onCreate(Bundle savedInstanceState) {
  20. super.onCreate(savedInstanceState);
  21. setContentView(R.layout.activity_main);
  22. MapView mapView = (MapView) findViewById(R.id.map);
  23. mapView.setClickable(true);
  24. mapView.setBuiltInZoomControls(true);
  25. TestOverlay overlay = new TestOverlay();
  26. mapView.getOverlays().add(overlay);
  27.  
  28. MapController mc = mapView.getController();
  29. mc.setZoom(21);
  30.  
  31. mapView.invalidate();
  32. }
  33.  
  34. @Override
  35. protected boolean isRouteDisplayed() {
  36. return false;
  37. }
  38.  
  39. static class TestOverlay extends Overlay {
  40. private Paint mPaint = new Paint();
  41. private Point mPoint1, mPoint2;
  42.  
  43. @Override
  44. public void draw(Canvas canvas, MapView mapView, boolean shadow) {
  45. super.draw(canvas, mapView, shadow);
  46. if (!shadow) {
  47. Projection pj = mapView.getProjection();
  48. GeoPoint center1 = mapView.getMapCenter();
  49. GeoPoint center2 = new GeoPoint(center1.getLatitudeE6(), center1.getLongitudeE6());
  50.  
  51. mPoint1 = pj.toPixels(center1, mPoint1);
  52. mPoint2 = pj.toPixels(center2, mPoint2);
  53.  
  54. mPaint.setStyle(Style.FILL);
  55. mPaint.setColor(0xff0000ff);
  56. canvas.drawCircle(mPoint1.x, mPoint1.y, 5, mPaint); // これはちゃんと中心になる
  57. mPaint.setColor(0xff00ff00);
  58. canvas.drawCircle(mPoint2.x, mPoint2.y, 5, mPaint); // スクロールしてるほどずれる
  59. }
  60. }
  61. }
  62. }
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty