androidgoogle-maps-api-3placeautocompletefragment

Use place autocomplete for place picker


I am working with placepicker in android to select a place and fetch details about the place. There is placeautocomplete fragment built in for place picker activity. when we provide any address there it will directly select that place and confirm dialog appears, I dont want that instead i want my location icon(Camera) to go to that location and then user choses unknown location if not available in autocomplete fragment.


Solution

  • To do that, you need to implement your own activity with 2 fragment in its layout: The first is the PlaceAutoComplete fragment

    <fragment
      android:id="@+id/place_autocomplete_fragment"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:name="com.google.android.gms.location.places.ui.PlaceAutocompleteFragment"
      />
    

    and the second is the GoogleMap fragment (or the View)

    In your activity you need to setup the PlaceSelectionListener and retrieve the Place from the PlaceAutoComplete.

    Now, you can use it for setting up a point on the map, focusing and zooming on it.