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);
}
}
}
我只想画一条连接代码中给出的两个地理坐标的线。这两个点正在显示,但我无法得到我想要画的线。我提到在谷歌地图上绘制一条线/路径,但输出不是我想要的。