2012-03-20 13 views
0

Navigatorベースのアプリケーションを使用すると、マップビューにOnTapとLongPressイベントを含める必要があります。タップをするとき、それは場所の長い緯度を示す必要があります。 LongPressを作成するときには、ターゲットなどとして使用するなど、いくつかのオプションが表示されます。誰でもこれらの出来事について考えてください。私自身はアンドロイドの初心者ですが、この助けに感謝します。親切に助けてください。MapViewのOnTapとLongPressListener

+0

を参照してくださいuの中で2タップを使用しています... http://stackoverflow.com/questions/1678493/android-maps-地図の使い方 - click-a-map – Kri

答えて

3

HII私はあなたを助けるかもしれない....リンクを以下試してみてください

/** 
* This Activity called when draw a fence on to the map. 
* 
* @author ketan kalariya([email protected]) 
* **/ 
public class AddFenceActivity extends FragmentMapActivity implements 
     SimpleGestureListener { 



    private List<Overlay> mapOverlays; 
    double[] location = new double[2]; 

    protected void onCreate(Bundle icicle) { 
     setTheme(THEME); 
     super.onCreate(icicle); 
     setContentView(R.layout.addfenceactivity); 

     mapView = (MapView) findViewById(R.id.addfenceactivity_mapview); 
     Log.d(TAG, "AddFence Activity come from Home Activity"); 
     id = getIntent().getIntExtra("ID", 0); 

     /** 
     * Access the overlay list. Returns: The list of overlays. 
     **/ 
     mapOverlays = mapView.getOverlays(); 

     myPrefs = getPreferences(MODE_PRIVATE); 
     mDetector = new SimpleGestureFilter(this, this); 

     MapController mapController = mapView.getController(); 

     mapView.setSatellite(false); 
     mapView.setBuiltInZoomControls(true); 

     Dataset = (GeoFencApplicationDataset) getApplicationContext(); 
     dbHelper = Dataset.getDbHelper(); 
     dbHelper.deleteTempTable(); 

    } 

    /** 
    * Destroy all fragments and loaders. 
    * 
    * **/ 
    protected void onDestroy() { 
     // TODO Auto-generated method stub 
     super.onDestroy(); 
    } 




    /** 
    * when it called.. The fence which is drawn on to map, it will be clear and 
    * lat/long stored in to preference and database table will become 
    * empty/null 
    **/ 
    private void MapClear() { 

     mapOverlays.clear(); 
     prefEdit = myPrefs.edit(); 
     prefEdit.putString("lat", ""); 
     prefEdit.putString("long", ""); 
     prefEdit.putString("srclat", ""); 
     prefEdit.putString("srclong", ""); 
     prefEdit.commit(); 
     mapView.invalidate(); 
     dbHelper.deleteTempTable(); 
     drawFlag = false; 

    } 

    /** 
    * For accounting purposes, the server needs to know whether or not you are 
    * currently displaying any kind of route information, such as a set of 
    * driving directions. 
    * 
    * @return True if route information is displayed; false otherwise. 
    **/ 
    protected boolean isRouteDisplayed() { 
     // TODO Auto-generated method stub 
     return false; 
    } 

    /** 
    * Called to process touch screen events. using mDetector object of 
    * SimpleGestureFilter call onTouchEvent 
    * 
    * @param mMotionEvent 
    *   The touch screen event. 
    * @return boolean Return true if this event was consumed. 
    **/ 
    public boolean dispatchTouchEvent(MotionEvent mMotionEvent) { 
     this.mDetector.onTouchEvent(mMotionEvent); 
     return super.dispatchTouchEvent(mMotionEvent); 
    } 

    /** 
    * when double click on to screen put first pin on map, consider first 
    * geoPoint. on second double click put second pin on map and draw path on 
    * map mapOvelay from fist point to second and insert all lat,long in 
    * database 
    * **/ 
    public void onDoubleTap(MotionEvent event) { 
     // TODO Auto-generated method stub 

     GeoPoint geoPoint = mapView.getProjection().fromPixels(
       (int) event.getX(), (int) event.getY() - 120); 

     srcLat = geoPoint.getLatitudeE6()/1E6; 
     srcLong = geoPoint.getLongitudeE6()/1E6; 

     Drawable marker = getApplicationContext().getResources().getDrawable(
       R.drawable.pin1); 
     mapView.getController().animateTo(geoPoint); 
     MapAddressOverlay itemizedOverlay = new MapAddressOverlay(marker); 
     itemizedOverlay.addOverlay(AddFenceActivity.this, srcLat, srcLong); 
     mapView.getOverlays().add(itemizedOverlay); 
     mapView.invalidate(); 

     if (!String.valueOf(srcLat).equals("") 
       || !String.valueOf(srcLong).equals("")) { 
     ...... 
.. 
. 
.. 

}