1
I’m finishing an application where I need to use the Google Maps API
for two things: select an address from the user’s choice (example: user navigates to the desired address and chooses it) and display the map based on the location of a predefined example (example: open the map at the address the user previously chose).
I read that it is possible to receive the selected address using the following code:
private GoogleMap mMap;
{...}
mMap.setOnMapClickListener(new OnMapClickListener() {
@Override
public void onMapClick(LatLng newLatLon) {
Toast.makeText(getApplicationContext(), point.toString(), Toast.LENGTH_SHORT).show();
}
});
But I would like to pass this function to an external button on the map. How can I do that? And although I looked up how to open a map using a pre-defined address, I couldn’t find anything I could handle. It is possible to pass a parameter of type String
for the API?
You would like to take the position centered on the map by clicking a button and not inside the Map (There is the method
getCameraPosition
)? To open the map in a preselected position you need to use the methodmoveCamera
(Setting up a camera updateCameraUpdate
) or use the methodanimateCamera
(same thing of moveCamera, however it is animated). Both solutions using the instance ofGoogleMap
.– Wakim
I don’t know if the centered position would be the right one for what I want. I want to get the name of the address of a street that was touched by the user and not its coordinates. I can do this with the
getCameraPosition
? I’ll look into themoveCamera
, thanks for the tip.– Renan Lazarotto
I understand the problem, you will have to use the API
GeoCoder
, that does the reverse of the location and provides you with a String with the approximate address of the position. Check out http://developer.android.com/training/location/display-address.html.– Wakim