如何在谷歌地图圈获得距离?

时间:2014-12-12 05:39:38

标签: android google-maps google-maps-api-3

我已经完成了这个

 I have created this Circle in Android by using google map API..

我想要这个

Now i want to add the distance text within the circle

我能够创建一个cirlce,但我想在圆圈内绘制一些半径文本,如果你有任何线索,请帮助我,我正在使用google api for android ..

1 个答案:

答案 0 :(得分:0)

你可以做的是使用addPlyline方法绘制线条,并可以创建一个自定义标记来显示距离。

画线:

map.addPolyline(new PolylineOptions()
  .add(new LatLng(lats, lons), new LatLng(late,lone))
  .width(5)
  .color(color));

创建自定义标记:

 map.addMarker(new MarkerOptions()
        .position(new LatLng(<Add a LatLng of center>)
        .title("100 Mi"));

在活动负荷下输入:

为此你需要创建一个标记,而不是使用map.addMarker使用它。

LatLng latlng= new LatLng(lat, lng);
    Marker marker= map.addMarker(new MarkerOptions()
                             .position(latlng)
                              .title("100 Mi"));
    marker.showInfoWindow();

使用ondraw方法在地图上绘制文字:

@Override
public void draw(Canvas canvas, MapView mapView, boolean shadow) {
Paint strokePaint = new Paint();
strokePaint.setARGB(255, 0, 0, 0);
strokePaint.setTextAlign(Paint.Align.CENTER);
strokePaint.setTextSize(16);
strokePaint.setTypeface(Typeface.DEFAULT_BOLD);
strokePaint.setStyle(Paint.Style.STROKE);
strokePaint.setStrokeWidth(2);

Paint textPaint = new Paint();
textPaint.setARGB(255, 255, 255, 255);
textPaint.setTextAlign(Paint.Align.CENTER);
textPaint.setTextSize(16);
textPaint.setTypeface(Typeface.DEFAULT_BOLD);

canvas.drawText("Some Text", 100, 100, strokePaint);
canvas.drawText("Some Text", 100, 100, textPaint);

super.draw(canvas, mapView, shadow);
}