Implement Sharing Location Places Picker same like WhatsApp without Places Picker Since it got deprecated
Asked Answered
H

1

13

We had a requirement of sharing location which is a similar kind of WhatsApp with respective to User Interface & functionality.

I have come across that Google Place Picker has got deprecated and also migrated to Places Clients.

Say Like as,

and when they are trying to search,

May be, I am not good at explaining my idea but overall I am in the search of the above kind of implementation.

And also I came to know that Google Charges for the search or the places from the below Url,

https://github.com/rtchagas/pingplacepicker

What all I have tired is,

Coding Part:

Places.initialize(applicationContext, "Google API Key")
placesClient = Places.createClient(this)



val autocompleteFragment =
          getSupportFragmentManager().findFragmentById(R.id.autocomplete_fragment) as AutocompleteSupportFragment

autocompleteFragment.setPlaceFields(Arrays.asList(Place.Field.ID, Place.Field.NAME));

autocompleteFragment.setOnPlaceSelectedListener(object : PlaceSelectionListener {
            override fun onPlaceSelected(p0: Place) {
                TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
            }

            override fun onError(p0: Status) {
                TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
            }
        });

 val intent = Autocomplete.IntentBuilder(
            AutocompleteActivityMode.FULLSCREEN, fields
        )
            .build(this);
        startActivityForResult(intent, AUTOCOMPLETE_REQUEST_CODE);

After searching for two three places I am get an error saying Retry. Don't know the reason.

Error:

enter image description here

Help is really appreciated.

Hippie answered 18/5, 2019 at 10:48 Comment(7)
Post your error log.Felice
Updated Question @FeliceHippie
Can you post error log?Hardie
I am starting an Intent AutocompleteActivityMode.FULLSCREEN.Hippie
do you really need places bar search ?Adrian
Suggest me if anything else can replace that ?Hippie
please check my suggestionAdrian
A
0

I faced the same problem since i'm working with place picker within my app , but since google decided to remove it , i have no choice than have a work around to find a solution !

i decided to use google map to recreate a place picker close experience .

First i created the map as full screen , and i putted an ImageView (Marker) as overlay of it as xml below :

<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/coordinator_layout"
xmlns:app="http://schemas.android.com/apk/res-auto">
<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <fragment
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/map"
        android:name="com.google.android.gms.maps.SupportMapFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context="com.streetdev.goodnecity.SelectLocationPicker" />
    <ImageView
        android:layout_centerInParent="true"
        android:src="@drawable/ic_map"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
</RelativeLayout>

<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="56dp"
    android:layout_height="56dp"
    app:backgroundTint="@color/colorPrimaryDark"
    android:src="@drawable/ic_plus"
    android:layout_margin="16dp"
    app:layout_anchor="@id/map"
    app:layout_anchorGravity="bottom|end" />
 </android.support.design.widget.CoordinatorLayout>

So whenever the user is navigating on the map , the marker will stay in the center of the map like place picker

Now all you have to do is start your map picker using startActivityForResult, you have to handle the cameraPosition with gps ( if its available ) and then as soon as you want to go back with the result ( for me i click on the Fab button ) , you can get the result this way :

            LatLng latng = mMap.getCameraPosition().target;
            Intent returnIntent = new Intent();
            returnIntent.putExtra("result",String.valueOf(latng.latitude)+";"+String.valueOf(latng.longitude));
            setResult(Activity.RESULT_OK,returnIntent);
            finish();

The last step is to handle the result in onActivityResult, you get your result , you do a split using ";" to separate latitude from longitude

hope my example will help some one !

Adrian answered 29/5, 2019 at 18:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.