อันนี้ผมเขียนเป็น class ไว้น่ะครับ
import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.Point; import android.location.Location; import com.google.android.maps.GeoPoint; import com.google.android.maps.MapView; import com.google.android.maps.Overlay; import com.google.android.maps.Projection; public class MapCircleUserMarker extends Overlay { private double latitude; private double longitude; private float radius_for_search_around; private final int TRANSPARENT_CIRCLE=25; //ค่าความโปร่งใส public MapCircleUserMarker() { this.radius_for_search_around = 100; //set default radius } public void setLatitudeLongtiudeRadiusSearchAround(Location L, float R){ this.latitude=L.getLatitude(); this.longitude=L.getLongitude(); this.radius_for_search_around=R; } @Override public boolean draw(Canvas canvas, MapView mapview, boolean shadow, long when) { super.draw(canvas, mapview, shadow); Projection projection = mapview.getProjection(); Point screenPts = new Point(); GeoPoint gop = new GeoPoint((int) (this.latitude * 1e6), (int) (this.longitude * 1e6)); projection.toPixels(gop, screenPts); float Lx = screenPts.x; float Ly = screenPts.y; Paint incircle = new Paint(); incircle.setColor(Color.rgb(46, 154, 254)); incircle.setAlpha(TRANSPARENT_CIRCLE); //set ความโปร่งใส่ 25% incircle.setAntiAlias(true); incircle.setStyle(Paint.Style.FILL); Paint strokecircle = new Paint(); float projectedRadius = projection.metersToEquatorPixels(radius_for_search_around); strokecircle.setColor(Color.rgb(46, 154, 254)); strokecircle.setAlpha(100); strokecircle.setAntiAlias(true); strokecircle.setStyle(Paint.Style.STROKE); strokecircle.setStrokeWidth(2); Paint outcircle = new Paint(); outcircle.setColor(Color.TRANSPARENT); outcircle.setAlpha(TRANSPARENT_CIRCLE - 5); //set ความโปร่งใส่ 25 - 5 = 20% outcircle.setAntiAlias(true); outcircle.setStyle(Paint.Style.STROKE); outcircle.setStrokeWidth(projectedRadius * (float)0.15); canvas.drawCircle(Lx, Ly, projectedRadius * (float)1.12 , outcircle); canvas.drawCircle(Lx, Ly, projectedRadius, incircle); canvas.drawCircle(Lx, Ly, projectedRadius, strokecircle); return true; } }
การเรียกใช้
MapView mapview = (MapView) findViewById(R.id.mapview); flaot radius_search_around = 150; RequestLocation requestl = new RequestLocation((LocationManager) getSystemService(Context.LOCATION_SERVICE)); MapCircleUserMarker mapcircleusermarker = new MapCircleUserMarker(); mapcircleusermarker.setLatitudeLongtiudeRadiusSearchAround( requestl.getLocation(), radius_search_around ); List<Overlay> list = mapview.getOverlays(); list.clear(); list.add(mapcircleusermarker);//class RequestLocation ผมได้เขียนเอาไว้แล้วน่ะครับในเรื่อง
GeoCoding and RequestLocation google map android
http://na5cent.blogspot.com/2012/03/geocoding-and-requestlocation-google.html
ผมขอ Source code เต็มๆได้มั้ยอ่ะครับ ผมทดลองทำตามแล้วแต่ยังเข้าไปหน้าจอ Google map ไมได้เลยอ่ะครับ มันขึ้นเออเร่อตลอดเลย
ตอบลบtue1991@hotmail.com