2010-12-15 117 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); 

     } 
    }); 
相关问题