as I know Google does not allow developers to customize place picker layout ,
so I want to make a place picker like the photo below.
it is from deliveroo app, I
This code works like a charm. However it seems that there are new updates to this as Google made new releases. Key differences are the following:
OnMapReadyCallback must be implemented:
public class InsertMapsActivity extends FragmentActivity implements LocationListener, OnMapReadyCallback
@Override public void onMapReady(GoogleMap googleMap) { this.googleMap = googleMap;
}
This code will no longer work:
// Getting reference to the SupportMapFragment of activity_main.xml
SupportMapFragment fm = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
// Getting GoogleMap object from the fragment
googleMap = fm.getMap();
Instead use this, which calls the callback in #1.
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
References to the googleMap object need be placed in the OnMapReady callback to ensure that the object is initially assigned else null pointer errors would occur:
@Override
public void onMapReady(GoogleMap googleMap) {
this.googleMap = googleMap;
// Enabling MyLocation Layer of Google Map
this.googleMap.setMyLocationEnabled(true);
googleMap.setOnMapClickListener(new GoogleMap.OnMapClickListener()
{
@Override
public void onMapClick(LatLng latLng)
{
googleMap.clear();
googleMap.addMarker(new MarkerOptions().position(latLng).title("Custom location").icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE)));
garageLocation = latLng;
}
});
}