3 import java
.io
.IOException
;
5 import java
.util
.Locale
;
7 import android
.content
.Context
;
8 import android
.graphics
.Bitmap
;
9 import android
.graphics
.BitmapFactory
;
10 import android
.graphics
.Canvas
;
11 import android
.graphics
.Paint
;
12 import android
.graphics
.Point
;
13 import android
.location
.Address
;
14 import android
.location
.Geocoder
;
15 import android
.view
.MotionEvent
;
16 import android
.widget
.Toast
;
18 import com
.google
.android
.maps
.GeoPoint
;
19 import com
.google
.android
.maps
.MapView
;
20 import com
.google
.android
.maps
.Overlay
;
21 import com
.weibo
.sina
.R
;
23 public class MapOverlay
extends Overlay
{
24 private Context mContext
;
25 private GeoPoint mGeoPoint
;
26 public MapOverlay(Context context
) {
32 public boolean onTouchEvent(MotionEvent event
, MapView mapView
) {
33 // ---when user lifts his finger---
34 if (event
.getAction() == 1) {
35 GeoPoint p
= mapView
.getProjection().fromPixels(
39 Geocoder geoCoder
= new Geocoder(
40 mContext
, Locale
.getDefault());
42 List
<Address
> addresses
= geoCoder
.getFromLocation(
43 p
.getLatitudeE6() / 1E6
,
44 p
.getLongitudeE6() / 1E6
, 1);
47 if (addresses
.size() > 0)
49 for (int i
=0; i
<addresses
.get(0).getMaxAddressLineIndex();
51 add
+= addresses
.get(0).getAddressLine(i
) + "\n";
54 Toast
.makeText(mContext
, add
, Toast
.LENGTH_SHORT
).show();
56 catch (IOException e
) {
66 public boolean draw(Canvas canvas
, MapView mapView
, boolean shadow
, long when
)
68 super.draw(canvas
, mapView
, shadow
);
69 Paint paint
= new Paint();
70 Point myScreenCoords
= new Point();
72 mapView
.getProjection().toPixels(mGeoPoint
, myScreenCoords
);
73 paint
.setStrokeWidth(1);
74 paint
.setARGB(255, 255, 0, 0);
75 paint
.setStyle(Paint
.Style
.STROKE
);
76 Bitmap bmp
= BitmapFactory
.decodeResource(mContext
.getResources(), R
.drawable
.ic_location_pin
);
77 canvas
.drawBitmap(bmp
, myScreenCoords
.x
, myScreenCoords
.y
, paint
);
78 canvas
.drawText("中通福瑞", myScreenCoords
.x
, myScreenCoords
.y
, paint
);
82 public GeoPoint
getGeoPoint() {
86 public void setGeoPoint(GeoPoint mGeoPoint
) {
87 this.mGeoPoint
= mGeoPoint
;