1

i am developing an application, in that i need to display googlemap(V2) and i need to get the address of the particular location when i touch on the map. I did this in previous version of google maps. In the new version i used the following code for dispalying the map, but i dont know how to get the address of the location when i touch on the map.

So, Please guide me how to implement this one.

 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);
Kevin Reid
  • 37,492
  • 13
  • 80
  • 108
koti
  • 1,071
  • 3
  • 15
  • 35

2 Answers2

3

Just add implemantation of OnMapClickListener to your map activity. Like :

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

Then :

 map.setOnMapClickListener(this);
    @Override
    public void onMapClick(LatLng arg0) {
        //Make Your implementation HERE
    }
Sercan Ozdemir
  • 4,641
  • 3
  • 34
  • 64
0

Combine OnMapClickListener as suggested by Sercan Ozdemir with Geocoder.getFromLocation.

Remember to use threads (AsyncTask) as Geocoder makes a network call to get the actual address.

Alternatively you can use geocoding API from Google, which is a bit more work (network communication, parsing).

MaciejGórski
  • 22,187
  • 7
  • 70
  • 94