1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | package irdc.ex10_06; import java.util.ArrayList; import java.util.List; import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.Point; import android.graphics.drawable.Drawable; import android.location.Location; import android.widget.Toast; import com.google.android.maps.GeoPoint; import com.google.android.maps.ItemizedOverlay; import com.google.android.maps.Overlay; import com.google.android.maps.MapView; import com.google.android.maps.OverlayItem; import com.google.android.maps.Projection; public class GeoPointImageOverlay extends ItemizedOverlay<OverlayItem> { public GeoPointImageOverlay(GeoPoint gp, int i) { this.geoLatitude = gp.getLatitudeE6(); this.geoLongitude = gp.getLongitudeE6(); // TODO Auto-generated constructor stub } private List<OverlayItem> items = new ArrayList<OverlayItem>(); private List<String> allRestaurantName; private double geoLatitude,geoLongitude; private Bitmap shadowIcon; private Location mLocation; private MapLocation selectedLocation; @Override public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) { shadowIcon = BitmapFactory.decodeResource(mapView.getResources(),R.drawable.shadow); Projection projection = mapView.getProjection(); if (shadow ) {shadowIcon = BitmapFactory.decodeResource(mapView.getResources(),R.drawable.shadow); GeoPoint gp = new GeoPoint((int)this.geoLatitude,(int)this.geoLongitude); /* 將Location轉成Point物件 */ Point point = new Point(); projection.toPixels(gp, point); /* 設定筆刷 */ Paint paint = new Paint(); paint.setAntiAlias(true); Bitmap bm = BitmapFactory.decodeResource(mapView.getResources(), R.drawable.bubble); canvas.drawBitmap(bm, point.x , point.y , paint); canvas.drawBitmap(shadowIcon, point.x + shadowIcon.getWidth()/3 , point.y + shadowIcon.getHeight()/2 ,paint ); } return super.draw(canvas, mapView, shadow, when); } public void updateLocation(Location location) { this.mLocation = location; } public Location getLocation() { return mLocation; } @Override protected OverlayItem createItem(int i) { // TODO Auto-generated method stub return null; } @Override public int size() { // TODO Auto-generated method stub return 0; } } |
Direct link: https://paste.plurk.com/show/298851