add weibo src
[freespace.git] / weibosrc / com / weibo / map / MapOverlay.java
bloba36fe4d2f179ab0a101d30d720492728d56c685d
1 package com.weibo.map;
3 import java.io.IOException;
4 import java.util.List;
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) {
27 super();
28 mContext = context;
31 @Override
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(
36 (int) event.getX(),
37 (int) event.getY());
39 Geocoder geoCoder = new Geocoder(
40 mContext, Locale.getDefault());
41 try {
42 List<Address> addresses = geoCoder.getFromLocation(
43 p.getLatitudeE6() / 1E6,
44 p.getLongitudeE6() / 1E6, 1);
46 String add = "";
47 if (addresses.size() > 0)
49 for (int i=0; i<addresses.get(0).getMaxAddressLineIndex();
50 i++)
51 add += addresses.get(0).getAddressLine(i) + "\n";
54 Toast.makeText(mContext, add, Toast.LENGTH_SHORT).show();
56 catch (IOException e) {
57 e.printStackTrace();
59 return true;
61 else
62 return false;
65 @Override
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();
71 // 将经纬度转换成实际屏幕坐标
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);
79 return true;
82 public GeoPoint getGeoPoint() {
83 return mGeoPoint;
86 public void setGeoPoint(GeoPoint mGeoPoint) {
87 this.mGeoPoint = mGeoPoint;