我最近开始使用谷歌地图v2,并发现很多事情已经改变。以前我使用的是Google Map v1,所以我使用的是MapView的概念。
我正在尝试使用five transparent circumcircles
创建center as my current location
。下面是代码,我用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();
}
}
扩展叠加并在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地图v2上绘制五个圆圈,方法是将当前位置作为圆心。意味着五个圆中的每一个具有相同的中心但具有不同的半径:第一个圆的半径为10米,第二个圆半径为20米,第三个圆半径为30米,第四个圆半径为40米,第五个圆半径为50米。我正在使用Google Maps v2。
我还需要在圆圈的中心显示一个标记。
我正在尝试这样的东西在谷歌地图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中创建此圈子时遇到问题。任何帮助将不胜感激。
答案 0 :(得分:4)
只需使用googleMap.addCircle(...)
更新
我完全按照我的说法去做,我做你想做的事情没有问题
这里是代码,超级简单的超级基本....
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
View view = super.onCreateView(inflater, container, savedInstanceState);
GoogleMap map = getMap();
int radius = 500;
for(int i=0; i<5; i++){
map.addCircle(new CircleOptions().center(new LatLng(0,0)).radius(radius).fillColor(0x30000000).strokeWidth(3));
radius += 500;
}
return view;
}