0

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.

Ali Khaki
  • 1,184
  • 1
  • 13
  • 24
Avi Patel
  • 475
  • 6
  • 23
  • Hi @AviPatel. Did you create your own activity and fragment or used directly the library's one? – Devster - Angelo Cimino Oct 21 '18 at 15:31
  • @CyanDeveloper-AngeloCimino, Its direct Activity that opens up.I haven't created any custom map activity for that. because i think this activity is what i was looking for the place selection. – Avi Patel Oct 21 '18 at 15:32
  • You can't edit the library's Classes. You need to implement the activity with a simple google map in your own layout including autocomplete search too. After that, you need to retrieve address from AutoComplete and put it as location in you google map, setting camera to focus and zoom on it. – Devster - Angelo Cimino Oct 21 '18 at 15:38
  • @CyanDeveloper-AngeloCimino, I got your point but there will be some way that i can just access map and get location that will be suggested to user by placeautocomplete fragment. I am trying to do it by implementing onPlaceSelected Listener hope it works :). – Avi Patel Oct 21 '18 at 15:40
  • yes.. and it is what I said.. Instead of using the library's activity, you need to create your own implementing a PlaceAutoComplete fragment and retrieving the location by its listener. After that, you need to pass that location to you GMap and set camera on it. – Devster - Angelo Cimino Oct 21 '18 at 15:49

1 Answers1

1

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.

  • well i know this approach, but wanted different approach by ready made activity that google provides, since that can't be possible i think i need to stick to this approach only, Thanks for the help buddy. – Avi Patel Oct 21 '18 at 16:03
  • @AviPatel have you tried the PlacePicker Intent instead? Look at this: https://cloud.google.com/maps-platform/places/ and scroll down to the example.. open the PlacePicker accordion and see the graphical example.. – Devster - Angelo Cimino Oct 21 '18 at 16:08
  • Yes my question was about that only i was using placepicker intent and it already has autocomplete fragment, but i cant move my location via place autocomplete fragment. It directly selects the place.I want option to just set marker on selected location and animate camera using placepicker intent. – Avi Patel Oct 21 '18 at 16:18
  • yes i know, hahah you didn't read the question properly, did you? – Avi Patel Oct 21 '18 at 16:22
  • Yes, I did, but you told about PlaceAutoComplete fragment, PlacePicker Intent and activities .. these are different things. So I had the doubt that you had not tried that solution. – Devster - Angelo Cimino Oct 21 '18 at 16:30
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/182225/discussion-between-avi-patel-and-cyan-developer-angelo-cimino). – Avi Patel Oct 21 '18 at 16:35