开发者

Drawing circles in android like in the google maps app

开发者 https://www.devze.com 2023-03-24 17:29 出处:网络
I would really like to know is there some tutorial or example on how to draw the blue circles that appear in the google maps app (the one that show you where u are). I would also like to know how when

I would really like to know is there some tutorial or example on how to draw the blue circles that appear in the google maps app (the one that show you where u are). I would also like to know how when u zoom in the circle becomes bigger (and when zooming out the circle becomes smaller and at some point disappears). If there are some s开发者_如何学Pythonuggestions or guides lines for this, or where to begin, I would really appreciate it. Thank u


After long looking for an answer I finally got a solution. Here is my code:

           int mToR= metersToRadius(55, mapView,p.getLatitudeE6());
           canvas.drawCircle(screenPts.x, screenPts.y, mToR, mPaintFill);
           canvas.drawCircle(screenPts.x, screenPts.y, mToR, mPaintStroke);

This draws the circle, where screenPts is a projection of the GeoPoint of my current location.

public static int metersToRadius(float meters, MapView map, double latitude) {
    return (int) (map.getProjection().metersToEquatorPixels(meters) * (1/ Math.cos(Math.toRadians(latitude))));         
}

This is how I calculate the radius of the circle. This I got from some other post (http://stackoverflow.com/questions/2077054/how-to-compute-a-radius-around-a-point-in-an-android-mapview)


Most drawing operations are available in the Canvas class: http://developer.android.com/reference/android/graphics/Canvas.html

As far as I know there is no direct way to draw the blue circles directly, but you should be able to emulate it closely through some calls to drawCircle()

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号