0

I have all the latest API's and SDK's installed on Android Studio. I have a Google maps API key. My app starts on my Note 4 perfectly in debug mode. It looks exactly the way it should - a Google map with a PlaceAutocompleteFragment search box on top of the map. However, when I select the PlaceAutocompleteFragment search box and type just one character into it, it starts a quick search wait circle then goes away, never returning any results. The app does not crash, it just goes back to the way it started. I could do this over and over without it crashing or the PlaceAutocompleteFragment returning any results.

java class:

public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {

private GoogleMap mMap;
/**
 * ATTENTION: This was auto-generated to implement the App Indexing API.
 * See https://g.co/AppIndexing/AndroidStudio for more information.
 */
private GoogleApiClient client;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_maps);
    // 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);
    // ATTENTION: This was auto-generated to implement the App Indexing API.
    // See https://g.co/AppIndexing/AndroidStudio for more information.
    client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();

    PlaceAutocompleteFragment fragment = (PlaceAutocompleteFragment)
            getFragmentManager().findFragmentById(R.id.place_autocomplete_fragment);

    fragment.setOnPlaceSelectedListener(new PlaceSelectionListener() {
        @Override
        public void onPlaceSelected(Place place) {
            // Handle the selected Place
            Context context = getApplicationContext();
            CharSequence text = place.getName();
            int duration = Toast.LENGTH_LONG;

            Toast toast = Toast.makeText(context, text, duration);
            toast.show();
        }

        @Override
        public void onError(Status status) {
            // Handle the error
        }
    });


}




/**
 * Manipulates the map once available.
 * This callback is triggered when the map is ready to be used.
 * This is where we can add markers or lines, add listeners or move the camera. In this case,
 * we just add a marker near Sydney, Australia.
 * If Google Play services is not installed on the device, the user will be prompted to install
 * it inside the SupportMapFragment. This method will only be triggered once the user has
 * installed Google Play services and returned to the app.
 */
@Override
public void onMapReady(GoogleMap googleMap) {
    mMap = googleMap;

    if(ContextCompat.checkSelfPermission(this,permission.ACCESS_FINE_LOCATION)
            ==PackageManager.PERMISSION_GRANTED)
    {
        mMap.setMyLocationEnabled(true);
        //mMap.moveCamera(CameraUpdateFactory.);
    }
    else
    {
        // Show rationale and request permission.
        // Add a marker in Miami and move the camera
        LatLng miami = new LatLng(26, -80);
        mMap.addMarker(new MarkerOptions().position(miami).title("Marker in Miami"));
        mMap.moveCamera(CameraUpdateFactory.newLatLng(miami));
    }
}


@Override
public void onStart() {
    super.onStart();

    // ATTENTION: This was auto-generated to implement the App Indexing API.
    // See https://g.co/AppIndexing/AndroidStudio for more information.
    client.connect();
    Action viewAction = Action.newAction(
            Action.TYPE_VIEW, // TODO: choose an action type.
            "Maps Page", // TODO: Define a title for the content shown.
            // TODO: If you have web page content that matches this app activity's content,
            // make sure this auto-generated web page URL is correct.
            // Otherwise, set the URL to null.
            Uri.parse("http://host/path"),
            // TODO: Make sure this auto-generated app deep link URI is correct.
            Uri.parse("android-app://com.greenfeetsurvival.greenfeetaviator/http/host/path")
    );
    AppIndex.AppIndexApi.start(client, viewAction);




}

@Override
public void onStop() {
    super.onStop();

    // ATTENTION: This was auto-generated to implement the App Indexing API.
    // See https://g.co/AppIndexing/AndroidStudio for more information.
    Action viewAction = Action.newAction(
            Action.TYPE_VIEW, // TODO: choose an action type.
            "Maps Page", // TODO: Define a title for the content shown.
            // TODO: If you have web page content that matches this app activity's content,
            // make sure this auto-generated web page URL is correct.
            // Otherwise, set the URL to null.
            Uri.parse("http://host/path"),
            // TODO: Make sure this auto-generated app deep link URI is correct.
            Uri.parse("android-app://com.greenfeetsurvival.greenfeetaviator/http/host/path")
    );
    AppIndex.AppIndexApi.end(client, viewAction);
    client.disconnect();
}
}

layout:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
map:uiZoomControls="true"
map:uiZoomGestures="true"
map:mapType="normal"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MapsActivity">
<fragment
    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.greenfeetsurvival.greenfeetaviator.MapsActivity">
    <android.support.v7.widget.CardView
        xmlns:card_view="http://schemas.android.com/apk/res-auto"
        android:id="@+id/card_view"
        android:layout_gravity="top"
        android:layout_margin="5dp"
        android:layout_width="200dp"
        android:layout_height="40dp"
        card_view:cardCornerRadius="4dp">
        <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" />
    </android.support.v7.widget.CardView>
</fragment>
</LinearLayout>

The manifest uses the gps location and internet:

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.INTERNET"/>

Please help.

Tom
  • 58
  • 3

2 Answers2

1

i also faced same problem. After adding a setOnPlaceSelectedListener to PlaceAutocompleteFragment, i found that reason is PLACES_API_ACCESS_NOT_CONFIGURED

mivi
  • 348
  • 5
  • 8
0

For others having this issue, there can be many reasons:

  1. Enable the Google places API.
  2. If there are other Google API's you are using, you should have different keys for each.
  3. If you are using Google Maps and Google places then you just need to define a single meta data tag in Android manifest:

    <meta-data
        android:name="com.google.android.geo.API_KEY"
        android:value="@string/google_maps_key" />
    
newman
  • 2,689
  • 15
  • 23
user2195058
  • 887
  • 7
  • 10