2013-05-11 66 views
1

中觸摸地圖從谷歌地圖(V2)獲取地址我正在開發一個應用程序,因爲我需要顯示googlemap(V2),並且我需要獲取特定位置的地址地圖。我在谷歌地圖的以前版本中做過。在新版本中,我使用下面的代碼來顯示地圖,但是當我觸摸地圖時,我不知道如何獲取位置的地址。如何通過在android

所以,請指導我如何實現這一個。

private GoogleMap map; 
final LatLng HAMBURG = new LatLng(current_latitude, current_longitude); 
map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap(); 
Marker hamburg = map.addMarker(new MarkerOptions().position(HAMBURG) 
     .title("Hamburg")); 
     // Move the camera instantly to hamburg with a zoom of 15. 
map.moveCamera(CameraUpdateFactory.newLatLngZoom(HAMBURG, 15)); 
    // Zoom in, animating the camera. 
map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null); 
+0

http://stackoverflow.com/questions/10580770/how-can-i-get-address-information-by-touching-screen-on-android-google-map – 2013-05-11 13:22:24

+0

http://mirnauman.wordpress.com/2012/04/16/android-google-maps-tutorial-part-6-getting-location-that-is-touched/ – 2013-05-11 13:23:05

+0

在V2中,我的答案引發了詭計! – 2013-05-11 14:00:30

回答

3

只需添加的OnMapClickListener implemantation到地圖的活動。像:

 public class GoogleMapActivity extends FragmentActivity implements 
     LocationSource,LocationListener,OnMapClickListener, 
     OnMapLongClickListener,OnMarkerDragListener, 
     OnMarkerClickListener 

然後:

map.setOnMapClickListener(this); 
    @Override 
    public void onMapClick(LatLng arg0) { 
     //Make Your implementation HERE 
    } 
0

結合OnMapClickListener由Sercan Ozdemir與Geocoder.getFromLocation建議。

請記住使用線程(AsyncTask)作爲Geocoder進行網絡調用以獲取實際地址。

或者,您可以使用geocoding API from Google,這是一個更多的工作(網絡通信,解析)。