0

Search bar is closing when I try to search for location.

When i click on Searchbar it appears for 1 second and disappears again. Tried to rebuild and clean my project but still no success.

statusCode=PLACES_API_ACCESS_NOT_CONFIGURED Error. Even tho i enabled the Places api on the same project or do i need to implement it into code somehow?

MapsActivity.java file -

public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {

private GoogleMap mMap;
private GoogleApiClient client;
PlaceAutocompleteFragment placeAutoComplete;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_maps2);
    placeAutoComplete = (PlaceAutocompleteFragment) getFragmentManager().findFragmentById(R.id.place_autocomplete);
    placeAutoComplete.setOnPlaceSelectedListener(new PlaceSelectionListener() {
        @Override
        public void onPlaceSelected(Place place) {

            Log.d("Maps", "Place selected: " + place.getName());
        }

        @Override
        public void onError(Status status) {
            Log.d("Maps", "An error occurred: " + status);
        }
    });

    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
            .findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);
}

@Override
public void onMapReady(GoogleMap googleMap) {
    mMap = googleMap;
    // Add a marker in Sydney and move the camera
    //LatLng sydney = new LatLng(-34, 151);
   // mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
    //mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
}


public void addMarker(Place p) {

    MarkerOptions markerOptions = new MarkerOptions();

    markerOptions.position(p.getLatLng());
    markerOptions.title(p.getName() + "");
    markerOptions.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE));

    mMap.addMarker(markerOptions);
    mMap.moveCamera(CameraUpdateFactory.newLatLng(p.getLatLng()));
    mMap.animateCamera(CameraUpdateFactory.zoomTo(13));

}

Manifest file -

<?xml version="1.0" encoding="utf-8"?>

<uses-permission android:name="android.permission.READ_CONTACTS" />
<!--
     The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
     Google Maps Android API v2, but you must specify either coarse or fine
     location permissions for the 'MyLocation' functionality. 
-->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".RegisterActivity" />

    <activity
        android:name=".MapsActivity"
        android:label="@string/title_activity_maps">
    </activity>

    <meta-data
        android:name="com.google.android.geo.API_KEY"
        android:value="my key is here" />
</application>

Krizs
  • 65
  • 8
  • Check in the console if this problem is happening https://i.stack.imgur.com/na0yE.png. This may happens if u haven't enabled the google map android API – androholic Jan 08 '18 at 18:42
  • Not the same error - [PICTURE WITH CONSOLE](https://image.prntscr.com/image/O4gN2W5uRYSmubkSZga3Aw.png) @avik Might be the disappearing is causing my mobile? Cause when i tried a demo app... it does the same thing. Android 7.0 – Krizs Jan 08 '18 at 18:54
  • Have u added this in your manifest : – androholic Jan 08 '18 at 18:57
  • `` Yes @avik – Krizs Jan 08 '18 at 18:59
  • Added manifest file. – Krizs Jan 08 '18 at 19:10
  • statusCode=PLACES_API_ACCESS_NOT_CONFIGURED – Krizs Jan 08 '18 at 19:43
  • See the step by step guide how to implement AutoComplete in your project .Look here this link[step by step guide to implement Autocomplete in our app.][2] [1]: https://developers.google.com/places/android-sdk/client-migration [2]: https://stackoverflow.com/questions/54965020/apiexception-9003-places-api-access-not-configured/54969500#54969500 Hope this will help you.Thanks..... – Rahul Kushwaha Mar 19 '19 at 12:42

0 Answers0