2010-12-15 113 views

回答

13

對於長時間點擊,我建議你退房http://www.kind-kristiansen.no/2010/handling-longpresslongclick-in-mapactivity/。這將詳細介紹如何偵聽Maps API中的長時間點擊事件,因爲我知道的內置功能很少或沒有。

至於lat/lng代碼,獲得長按後,您可以將像素轉換爲座標。

public void recieveLongClick(MotionEvent ev) 
{ 
    Projection p = mapView.getProjection(); 
    GeoPoint geoPoint = p.fromPixels((int) ev.getX(), (int) ev.getY()); 
    // You can now pull lat/lng from geoPoint 
} 
+3

鏈接在這個答案指向一個博客帖子我寫了一段時間回來。我剛剛寫了一篇新文章,提供了一個更清潔,效果更好的解決方案。這可能是有趣的:http://www.kind-kristiansen.no/2011/android-handling-longpresslongclick-on-map-revisited/ – rogerkk 2011-04-19 10:30:32

4

你必須管理LongClick事件,然後使用代碼,找出經度和緯度與下面的代碼:

GeoPoint geoPoint=mapView.getProjection().fromPixels((int)event.getX(),(int)event.getY()); 
int latitude = geoPoint.getLatitudeE6(); 
int longitude = geoPoint.getLongitudeE6(); 

其中「事件」是「MotionEvent」的對象。

根據您的情況使用任何其他事件。

0

它提供經度和緯度上的地圖點點擊

map.setOnMapClickListener(new OnMapClickListener() { 

     @Override 
     public void onMapClick(LatLng point) { 
      //myMap.addMarker(new MarkerOptions().position(point).title(point.toString())); 

       //The code below demonstrate how to convert between LatLng and Location 

       //Convert LatLng to Location 
       Location location = new Location("Test"); 
       location.setLatitude(point.latitude); 
       location.setLongitude(point.longitude); 
       location.setTime(new Date().getTime()); //Set time as current Date 
       txtinfo.setText(location.toString()); 

       //Convert Location to LatLng 
       LatLng newLatLng = new LatLng(location.getLatitude(), location.getLongitude()); 

       MarkerOptions markerOptions = new MarkerOptions() 
         .position(newLatLng) 
         .title(newLatLng.toString()); 

       map.addMarker(markerOptions); 

     } 
    }); 
相關問題