【发布时间】:2013-05-21 21:00:15
【问题描述】:
我最近开始使用 Google Map v2 并发现很多事情都发生了变化。之前我使用的是 Google Map v1,所以我使用的是 MapView 的概念。
我正在尝试使用center as my current location 创建five transparent circumcircles。下面是代码,我使用Google Map v1 来绘制圆圈,它对我来说工作得很好。现在我正在尝试在Google Map v2 的下面的代码中绘制相同的圆圈。我不能在这里使用 MapView,因为我在这里使用 GoogleMap 对象。谁能帮我在 Google Map v2 上以我当前位置为中心绘制圆圈
@Override
public void onLocationChanged(Location location) {
if (location != null) {
GeoPoint point = new GeoPoint(
(int) (location.getLatitude() * 1E6),
(int) (location.getLongitude() * 1E6));
// Create a LatLng object for the current location
LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());
// Show the location on the Google Map
googleMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
// Zoom in the Google Map
googleMap.animateCamera(CameraUpdateFactory.zoomTo(15));
// Below is the code for Google Map v1 to draw the circle on the map
// if (mapOverlay == null) {
// mapOverlay = new MapOverlay(this, R.drawable.mark_blue);
// List<Overlay> listOfOverlays = mapView.getOverlays();
// listOfOverlays.add(mapOverlay);
// }
// mapOverlay.setPointToDraw(point);
// mapView.invalidate();
}
}
一个简单的类,扩展 Overlay 并在 Google Map v1 上绘制圆圈
class MapOverlay extends Overlay {
private GeoPoint pointToDraw;
int[] imageNames = new int[6];
// This is the cached Point on the screen that will get refilled on
// every draw
private Point mScreenPoints;
// This is the cached decoded bitmap that will be drawn each time
private Bitmap mBitmap;
// Cached Paint
private Paint mCirclePaint;
public MapOverlay(ProximityLocationListener gpsLocationListener,
int currentUser) {
imageNames[0] = currentUser;
imageNames[1] = R.drawable.tenm;
imageNames[2] = R.drawable.twentym;
imageNames[3] = R.drawable.thirtym;
imageNames[4] = R.drawable.fourtym;
imageNames[5] = R.drawable.fiftym;
// This only needs to be made here, once. It never needs to change.
mCirclePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mCirclePaint.setColor(0x10000000);
mCirclePaint.setStyle(Style.FILL_AND_STROKE);
// We only need to load this image once and then just keep drawing
// it when dirtyed.
mBitmap = BitmapFactory.decodeResource(getResources(),
imageNames[0]);
// This Point object will be changed every call to toPixels(), but
// the instance can be recycled
mScreenPoints = new Point();
}
public void setPointToDraw(GeoPoint point) {
pointToDraw = point;
}
public GeoPoint getPointToDraw() {
return pointToDraw;
}
@Override
public boolean draw(Canvas canvas, MapView mapView, boolean shadow,
long when) {
super.draw(canvas, mapView, shadow);
mScreenPoints = mapView.getProjection().toPixels(pointToDraw,
mScreenPoints);
int totalCircle = 5;
int radius = 40;
int centerimagesize = 13;
for (int i = 1; i <= totalCircle; i++) {
canvas.drawCircle(mScreenPoints.x + 18, mScreenPoints.y + 36, i
* radius, mCirclePaint);
canvas.drawBitmap(BitmapFactory.decodeResource(getResources(),
imageNames[i]), ((mScreenPoints.x) + (i * radius)),
(mScreenPoints.y), null);
}
canvas.drawBitmap(mBitmap,
(mScreenPoints.x - (centerimagesize / 2)),
(mScreenPoints.y - (centerimagesize / 2)), null);
super.draw(canvas, mapView, shadow);
return true;
}
}
我只需要在 Google Map v2 上绘制与上述代码相同的圆圈。有什么办法,我可以将上面的代码与 GoogleMap 对象一起使用,以便我可以在 Google Map v2 上绘制圆圈?
感谢您的帮助。
更新代码:-
我需要以当前位置为圆心,在 Google Maps v2 上绘制五个圆。这意味着五个圆中的每一个都具有相同的中心但具有不同的半径:第一个圆的半径为 10m,第二个圆的半径为 20m,第三个圆的半径为 30m,第四个圆的半径为 40m,第五个圆的半径为 50m。我正在使用谷歌地图 v2。
我还需要在圆的中心显示一个标记。
我正在尝试这样的方法在 Google Map v2 上画圆,但它只画了一个圆而不是五个外接圆
CircleOptions circleOptions = new CircleOptions()
.center(latLng) //set center
.radius(500) //set radius in meters
.fillColor(Color.TRANSPARENT) //default
.strokeColor(0x10000000)
.strokeWidth(5);
myCircle = googleMap.addCircle(circleOptions);
我需要像这样画外接圆-
谁能帮我解决这个问题?我在 Google Map v2 中制作这个圆圈时遇到问题。任何帮助将不胜感激。
【问题讨论】:
标签: java android google-maps-api-2