私はAndroidが初めてです。私は自分のアプリケーションである場所から別の場所に線を描きたい。 Androidで2点間の線を描くにはどうすればよいですか?私を助けてください。AndroidでGoogleマップの2点間に線を描くにはどうすればよいですか?
1
A
答えて
1
マップにOverlay
を追加して、それを無効にして、onDraw()
メソッドを上書きする必要があります。そうすれば、地図上にあなたが望むものを描くことができます。
0
使用このそれは私のため
mapView.setBuiltInZoomControls(true);
mapController = mapView.getController();
ArrayList allGeoPoints = getDirections(8.487495, 76.948623,toLat 10.015861, 76.341867toLon);
GeoPoint moveTo = new GeoPoint(startLattitude, startLongigude);
mapController.setCenter(moveTo);
//mc.animateTo(moveTo);
mapController.setZoom(12);
mapView.getOverlays().add(new MyOverlay(allGeoPoints));
public static ArrayList getDirections(double lat1, double lon1, double lat2, double lon2) {
String url = "http://maps.googleapis.com/maps/api/directions/xml?origin=" +lat1 + "," + lon1 + "&destination=" + lat2 + "," + lon2 + "&sensor=false&units=metric";
String tag[] = { "lat", "lng" };
ArrayList listOfGeopoints = new ArrayList();
HttpResponse response = null;
try {
HttpClient httpClient = new DefaultHttpClient();
HttpContext localContext = new BasicHttpContext();
HttpPost httpPost = new HttpPost(url);
response = httpClient.execute(httpPost, localContext);
InputStream in = response.getEntity().getContent();
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = builder.parse(in);
Log.e("********************** ",new JsonOperations().convertStreamToString(in).toString());
if (doc != null) {
NodeList nl1, nl2;
nl1 = doc.getElementsByTagName(tag[0]);
nl2 = doc.getElementsByTagName(tag[1]);
if (nl1.getLength() > 0) {
listOfGeopoints = new ArrayList();
for (int i = 0; i < nl1.getLength(); i++) {
Node node1 = nl1.item(i);
Node node2 = nl2.item(i);
double lat = Double.parseDouble(node1.getTextContent());
double lng = Double.parseDouble(node2.getTextContent());
listOfGeopoints.add(new GeoPoint((int) (lat * 1E6), (int) (lng * 1E6)));
}
} else {
// No points found
}
}
} catch (Exception e) {
e.printStackTrace();
}
return listOfGeopoints;
}
そしてmyoverlayクラス
public class MyOverlay extends Overlay {
private ArrayList allGeoPoints;
public MyOverlay(ArrayList allGeoPoints) {
super();
this.allGeoPoints = allGeoPoints;
}
@Override
public boolean draw(Canvas canvas, MapView mv, boolean shadow, long when) {
super.draw(canvas, mv, shadow);
drawPath(mv, canvas);
return true;
}
public void drawPath(MapView mv, Canvas canvas) {
int xPrev = -1, yPrev = -1, xNow = -1, yNow = -1;
Paint paint = new Paint();
paint.setColor(Color.BLUE);
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeWidth(4);
//paint.setAlpha(100);
if (allGeoPoints != null)
for (int i = 0; i < allGeoPoints.size() - 4; i++) {
GeoPoint gp = (GeoPoint) allGeoPoints.get(i);
Point point = new Point();
mv.getProjection().toPixels(gp, point);
xNow = point.x;
yNow = point.y;
if (xPrev != -1) {
canvas.drawLine(xPrev, yPrev, xNow, yNow, paint);
}
xPrev = xNow;
yPrev = yNow;
}
}
}
関連する問題
- 1. Googleマップapiを使用して点線円を描くにはどうすればよいですか?
- 2. matplotlibに破線/点線の端でマーカーを描くにはどうすればよいですか?
- 3. Google棒グラフの棒グラフ間に平均線を描くにはどうすればよいですか?
- 4. 2つのdivの間に線を描くにはどうすればよいですか?
- 5. 主要なグリッド線の間に小さなグリッド線を描くにはどうすればよいですか?
- 6. Googleマップのスウィフトで点線( - )半径を描く方法は?
- 7. JavaFXの2つの点の間に矢印を描くにはどうすればいいですか?
- 8. javaFxに複数の点を含む線を描くにはどうすればよいですか?
- 9. d3v4の2点間にどのように矢印を描くのですか?
- 10. ggplot2で2つの線の間に密度マップをプロットするにはどうすればよいですか?
- 11. Googleマップでポリラインの中間ループを描画するにはどうすればよいですか?
- 12. シヌソイド線グラフを描くにはどうすればよいですか?
- 13. openLayersで水平線を描くにはどうすればいいですか?
- 14. Googleマップに何百万という点を描くには?
- 15. iReportに縦線を描くにはどうすればいいですか?
- 16. サブプロットに対角線を描くにはどうすればいいですか?
- 17. A点からB点に線を描画するにはどうすればいいですか?
- 18. Googleマップでカラフルなパスを描くにはどうすればよいですか?
- 19. GoogleマップV3で楕円形を描くにはどうすればよいですか?
- 20. Android webviewでマスク(円)を描くにはどうすればよいですか?
- 21. svgは2点の間に点線のベルカーブを描きます
- 22. ペグマンのパスに沿ってGoogleマップにポリラインを描くにはどうすればいいですか?
- 23. Google Maps Androidで曲線の破線を描くことはできますか? Googleマップで
- 24. Googleマップに線を描く方法
- 25. Googleマップの2か所の間で経路指定の方法を描くにはどうすればよいですか?
- 26. 2つ以上のビューを結ぶ線を描くにはどうすればよいですか?
- 27. このグラフに線形回帰直線を描くにはどうすればよいですか?
- 28. どのように2つの点から線を引いて、線をopencv、pythonで輪郭点に達するまで描くことができますか?
- 29. iPhoneに線を描画するにはどうすればよいですか?
- 30. JComponentのペイントメソッドから点線を描画するにはどうすればよいですか?
行き方やラインを正常に動作しますか? – zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz