Reputation: 17
I have used the below code to search for places in my application.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
PlaceAutocompleteFragment autocompleteFragment = (PlaceAutocompleteFragment)
getFragmentManager().findFragmentById(R.id.place_autocomplete_fragment);
autocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() {
@Override
public void onPlaceSelected(Place place) {
mGoogleMap.clear();
mGoogleMap.addMarker(new MarkerOptions().position(place.getLatLng()).title(String.valueOf(place.getName())));
mGoogleMap.moveCamera(CameraUpdateFactory.newLatLng(place.getLatLng()));
mGoogleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(place.getLatLng(), 12.0f));
}
But whenever I click the search box, it appears for a second and then disappears.
Please clarify my doubt.
Upvotes: 1
Views: 1253
Reputation: 3709
This is common issue when developing with Google Maps Platform.
Please follow these steps:
1- Login to Google Cloud Console.
2- Select or Create your associated project with API KEY.
3- Enable Places API in Console
To get a API key check Setup API KEY
Upvotes: 1