I'm using the google places API ( payment activated ) I get the key, when added it to my application the search works well, but, the map itself not working it shows blank and below I can see the google logo
my XML
<fragment
android:id="@+id/map_fragment"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
and my java code for declare the places API & map
private void initMapsAndPlaces() {
mFusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(this);
Places.initialize(this, mApiKey);
placesClient = Places.createClient(this);
final AutocompleteSessionToken token = AutocompleteSessionToken.newInstance();
MapFragment mapFragment = (MapFragment) getFragmentManager().findFragmentById(R.id.map_fragment);
mapFragment.getMapAsync(this);
mapView = mapFragment.getView();
materialSearchBar.setOnSearchActionListener(new MaterialSearchBar.OnSearchActionListener() {
@Override
public void onSearchStateChanged(boolean enabled) {
}
@Override
public void onSearchConfirmed(CharSequence text) {
startSearch(text.toString(), true, null, true);
}
@Override
public void onButtonClicked(int buttonCode) {
if (buttonCode == MaterialSearchBar.BUTTON_BACK) {
materialSearchBar.disableSearch();
materialSearchBar.clearSuggestions();
}
}
});
materialSearchBar.addTextChangeListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
FindAutocompletePredictionsRequest predictionsRequest = FindAutocompletePredictionsRequest.builder()
.setCountry(mCountry)
.setSessionToken(token)
.setQuery(s.toString())
.build();
placesClient.findAutocompletePredictions(predictionsRequest).addOnCompleteListener(new OnCompleteListener<FindAutocompletePredictionsResponse>() {
@Override
public void onComplete(@NonNull Task<FindAutocompletePredictionsResponse> task) {
if (task.isSuccessful()) {
FindAutocompletePredictionsResponse predictionsResponse = task.getResult();
if (predictionsResponse != null) {
predictionList = predictionsResponse.getAutocompletePredictions();
List<String> suggestionsList = new ArrayList<>();
for (int i = 0; i < predictionList.size(); i++) {
AutocompletePrediction prediction = predictionList.get(i);
suggestionsList.add(prediction.getFullText(null).toString());
}
materialSearchBar.updateLastSuggestions(suggestionsList);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
if (!materialSearchBar.isSuggestionsVisible()) {
materialSearchBar.showSuggestionsList();
}
}
}, 1000);
}
} else {
Log.i(TAG, "prediction fetching task unSuccessful");
}
}
});
}
@Override
public void afterTextChanged(Editable s) {
}
});
materialSearchBar.setSuggestionsClickListener(new SuggestionsAdapter.OnItemViewClickListener() {
@Override
public void OnItemClickListener(int position, View v) {
if (position >= predictionList.size()) {
return;
}
AutocompletePrediction selectedPrediction = predictionList.get(position);
String suggestion = materialSearchBar.getLastSuggestions().get(position).toString();
materialSearchBar.setText(suggestion);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
materialSearchBar.clearSuggestions();
}
}, 1000);
InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
if (imm != null) {
imm.hideSoftInputFromWindow(materialSearchBar.getWindowToken(), InputMethodManager.HIDE_IMPLICIT_ONLY);
}
String placeId = selectedPrediction.getPlaceId();
List<Place.Field> placeFields = Arrays.asList(Place.Field.LAT_LNG, Place.Field.NAME, Place.Field.ADDRESS);
FetchPlaceRequest fetchPlaceRequest = FetchPlaceRequest.builder(placeId, placeFields).build();
placesClient.fetchPlace(fetchPlaceRequest).addOnSuccessListener(new OnSuccessListener<FetchPlaceResponse>() {
@Override
public void onSuccess(FetchPlaceResponse fetchPlaceResponse) {
Place place = fetchPlaceResponse.getPlace();
Log.i(TAG, "place found " + place.getName() + place.getAddress());
LatLng latLng = place.getLatLng();
if (latLng != null) {
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, DEFAULT_ZOOM));
}
rippleBg.startRippleAnimation();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
rippleBg.stopRippleAnimation();
}
}, 2000);
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
if (e instanceof ApiException) {
ApiException apiException = (ApiException) e;
apiException.printStackTrace();
int statusCode = apiException.getStatusCode();
Log.i(TAG, "place not found" + e.getMessage());
Log.i(TAG, "status code : " + statusCode);
}
}
});
}
@Override
public void OnItemDeleteListener(int position, View v) {
}
});
}
permissions are added
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
can anyone help me, please?
if anyone still suffering
after a long time of the search, I missed adding
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="@string/places_api_key" />
to manifest file.