package com.chleon.mapviewdemo;
import java.util.List;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Point;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;
import com.google.android.maps.Projection;
public class MainActivity extends MapActivity {
Projection projection;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
MapView mapView = (MapView) findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);
List<Overlay> mapOverlays = mapView.getOverlays();
Drawable drawable = this.getResources().getDrawable(
R.drawable.ic_action_search);
HelloItemizedOverlay itemizedoverlay = new HelloItemizedOverlay(
drawable, this);
int latitude1 = (int) (28.619087 * 1e6);
int longitude1 = (int) (77.376867 * 1e6);
GeoPoint point = new GeoPoint(latitude1, longitude1);
OverlayItem overlayitem = new OverlayItem(point, "Prashant",
"I'm somewhere near delhi");
GeoPoint point2 = new GeoPoint(17385812, 78480667);
OverlayItem overlayitem2 = new OverlayItem(point2, "Prashant",
"I'm in Hyderabad");
itemizedoverlay.addOverlay(overlayitem);
itemizedoverlay.addOverlay(overlayitem2);
mapOverlays.add(itemizedoverlay);
}
protected boolean isRouteDisplayed() {
return false;
}
class MyOverlay extends Overlay {
public MyOverlay() {
}
public void draw(Canvas canvas, MapView mapView, boolean shadow) {
super.draw(canvas, mapView, shadow);
Paint mPaint = new Paint();
mPaint.setDither(true);
mPaint.setColor(Color.RED);
mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
mPaint.setStrokeJoin(Paint.Join.ROUND);
mPaint.setStrokeCap(Paint.Cap.ROUND);
mPaint.setStrokeWidth(6);
int latitude1 = (int) (28.619087 * 1e6);
int longitude1 = (int) (77.376867 * 1e6);
projection = mapView.getProjection();
GeoPoint point = new GeoPoint(latitude1, longitude1);
GeoPoint point2 = new GeoPoint(17385812, 78480667);
Point p1 = new Point();
Point p2 = new Point();
Path path = new Path();
projection.toPixels(point, p1);
projection.toPixels(point2, p2);
path.moveTo(p2.x, p2.y);
path.lineTo(p1.x, p1.y);
canvas.drawPath(path, mPaint);
}
}
}
コードで指定された2つの地理座標を結ぶ線を描きたいだけです。2つの点が表示されていますが、描きたい線を取得できません。Drawing a line/path on Google Mapsを参照しましたが、出力は私が望むものではありません。