精華區beta Android 關於我們 聯絡資訊
※ 引述《barry198744 (小豪)》之銘言: : 請問一下唷~ : 一般的在Google Map上的應用,多半都是GeoPoint的座標轉成螢幕的Poxels座標, : 然後畫圖在螢幕上,可是今天我想要反過來,就是我用手去碰觸螢幕上的地圖,然 : 後抓出地圖上被我碰到的點的座標是多少,這樣的話我應該怎樣做呢><~ : 感謝!! http://www.anddev.org/viewtopic.php?p=28140 @Override public void onCreate(Bundle icicl){ ............. ............. OnTouchListener myOnTouchListener=new OnTouchListener(){ public boolean onTouch(View mapView,MotionEvent m){ int action=m.getAction(); switch(action){ case MotionEvent.ACTION_UP: int x=(int)m.getX(); int y=(int)m.getY(); double latspan=(myMapView.getLatitudeSpan()/1.0E6); double lngspan=(myMapView.getLongitudeSpan()/1.0E6); GeoPoint center=myMapView.getMapCenter(); double xpcent=(x/(double)myMapView.getWidth()); double ypcent=(y/(double)myMapView.getHeight()); double lat0=(center.getLatitudeE6()/1.0E6+(latspan/2.0)); double lng0=(center.getLongitudeE6()/1.0E6-(lngspan/2.0)); double lat=lat0-(ypcent*latspan); double lng=lng0+(xpcent*lngspan); Log.i("x=",""+x); Log.i("y=",""+y); GeoPoint newpoint=new GeoPoint((int)(lat*1E6),(int)(lng*1E6)); // myMapView.getController().zoomOut(); Log.i("Map","Height"+myMapView.getHeight()); Log.i("Map","width"+myMapView.getWidth()); Log.i("Current","LatitudeSpane"+myMapView.getLatitudeSpan()); Log.i("Current","LongitudeSpan"+myMapView.getLongitudeSpan()); Log.i("center Longitude","is"+newpoint.getLongitudeE6()); Log.i("center","Latitude is"+newpoint.getLatitudeE6()); Log.i("new ","latitude "+lat); Log.i("new","longitude "+lng); Log.i("background","is"+myMapView.getBackground()); Log.i("Zoom in","works"); myMapView.invalidate(); mc.animateTo(newpoint); mc.zoomIn(); break; } return false; } }; myMapView.setOnTouchListener(myOnTouchListener); ...... ..... } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.114.78.145
terrybob:感謝推 03/02 02:04
tynus:推 03/02 11:22