У меня проблема в моем проекте. когда я щелкаю панель поиска в верхней части экрана, затем показываю ошибку, ошибка:
status (statuscode = place_api_access_not_configured resolution = null)
мое место api включено, но Я все еще получаю сообщение об ошибке.
Вот мой Добро пожаловать. java
public class Welcome extends FragmentActivity implements OnMapReadyCallback,
GoogleApiClient.ConnectionCallbacks,
GoogleApiClient.OnConnectionFailedListener,
LocationListener
{
private GoogleMap mMap;
private static final int MY_PERMISSION_REQUEST_CODE=7000;
private static final int PLAY_SERIVICES_RES_REQUEST=7001;
private LocationRequest mLocationRequest;
private GoogleApiClient mGoogleApiClient;
private Location lastLocation;
private static int UPDATE_INTERVAL=5000;
private static int FATEST_INTERVAL=3000;
private static int DISPLACEMENT=10;
DatabaseReference drivers;
GeoFire geoFire;
Marker mCurrent;
Switch location_switch;
SupportMapFragment mapFragment;
//car animation...
private List<LatLng> polyLineList;
private Marker carMarker;
private float v;
private double lat,lng;
private Handler handler;
private LatLng startPosition,endPosition,currentPosition;
private int index,next;
//private Button btnGo;
private PlaceAutocompleteFragment places;
private String destination;
private PolylineOptions polylineOptions,blackPolylineOptions;
private Polyline blackPolyline,greyPolyline;
private IGoogleAPI mService;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_welcome);
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
//init view..
location_switch= findViewById(R.id.location_switch);
location_switch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isOnline) {
if(isOnline)
{
startLocationUpdate();
displayLocation();
Snackbar.make(mapFragment.getView(),"You are Online",Snackbar.LENGTH_SHORT).show();
}
else
{
stopLocationUpdate();
mCurrent.remove();
mMap.clear();
//handler.removeCallbacks(drawPathRunnable);
Snackbar.make(mapFragment.getView(),"You are Offline",Snackbar.LENGTH_SHORT).show();
}
}
});
polyLineList=new ArrayList<>();
//places Api....
places=(PlaceAutocompleteFragment)getFragmentManager().findFragmentById(R.id.place_autocomplete_fragment);
places.setOnPlaceSelectedListener(new PlaceSelectionListener() {
@Override
public void onPlaceSelected(Place place) {
if(location_switch.isChecked())
{
destination=place.getAddress().toString();
destination=destination.replace(" ","+");
getDirection();
}
else {
Toast.makeText(Welcome.this, "Please Change your status in Online", Toast.LENGTH_SHORT).show();
}
}
@Override
public void onError(Status status) {
Toast.makeText(Welcome.this, ""+status.toString(), Toast.LENGTH_SHORT).show();
}
});
//Geo fire
drivers= FirebaseDatabase.getInstance().getReference("Drivers");
geoFire=new GeoFire(drivers);
setUpLocation();
mService= Common.getGoogleAPI();
}
//we request run time permission ,we need override OnRequestPermission Result..
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
switch (requestCode)
{
case MY_PERMISSION_REQUEST_CODE:
if(grantResults.length>0&&grantResults[0]==PackageManager.PERMISSION_GRANTED)
{
if(checkPlayServices())
{
buildGoogleApiClient();
createLocationRequest();
if(location_switch.isChecked())
displayLocation();
}
}
}
}
private void setUpLocation() {
if(ActivityCompat.checkSelfPermission(this,Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED &&
ActivityCompat.checkSelfPermission(this,Manifest.permission.ACCESS_FINE_LOCATION) !=PackageManager.PERMISSION_GRANTED)
{
//Request Runtime permission...
ActivityCompat.requestPermissions(this,new String[]{
Manifest.permission.ACCESS_COARSE_LOCATION,
Manifest.permission.ACCESS_FINE_LOCATION
},MY_PERMISSION_REQUEST_CODE);
}
else
{
if(checkPlayServices())
{
buildGoogleApiClient();
createLocationRequest();
if(location_switch.isChecked())
displayLocation();
}
}
}
private void createLocationRequest() {
mLocationRequest=new LocationRequest();
mLocationRequest.setInterval(UPDATE_INTERVAL);
mLocationRequest.setFastestInterval(FATEST_INTERVAL);
mLocationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);
mLocationRequest.setSmallestDisplacement(DISPLACEMENT);
}
private void buildGoogleApiClient() {
mGoogleApiClient=new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.build();
mGoogleApiClient.connect(); //Connected Google api client.....
}
private boolean checkPlayServices() {
int resultCode= GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
if(resultCode!=ConnectionResult.SUCCESS)
{
if(GooglePlayServicesUtil.isUserRecoverableError(resultCode))
GooglePlayServicesUtil.getErrorDialog(resultCode,this,PLAY_SERIVICES_RES_REQUEST).show();
else {
Toast.makeText(this, "This device is not supported ", Toast.LENGTH_SHORT).show();
}
return false;
}
return true;
}
private void stopLocationUpdate() {
if(ActivityCompat.checkSelfPermission(this,Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED &&
ActivityCompat.checkSelfPermission(this,Manifest.permission.ACCESS_FINE_LOCATION) !=PackageManager.PERMISSION_GRANTED)
{
return;
}
LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient,(com.google.android.gms.location.LocationListener) this);
}
private void displayLocation() {
if(ActivityCompat.checkSelfPermission(this,Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED &&
ActivityCompat.checkSelfPermission(this,Manifest.permission.ACCESS_FINE_LOCATION) !=PackageManager.PERMISSION_GRANTED)
{
return;
}
lastLocation=LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
if(lastLocation!=null)
{
if(location_switch.isChecked())
{
final double latitude=lastLocation.getLatitude();
final double longitude=lastLocation.getLongitude();
//update firebase..
geoFire.setLocation(FirebaseAuth.getInstance().getCurrentUser().getUid(), new GeoLocation(latitude, longitude), new GeoFire.CompletionListener() {
@Override
public void onComplete(String key, DatabaseError error) {
//add marker
if(mCurrent!=null)
mCurrent.remove();//marker remove already
mCurrent=mMap.addMarker(new MarkerOptions()
.position(new LatLng(latitude,longitude))
.title("YOUR LOCATION"));
//Move camera from this position..
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(latitude,longitude),15.0f));
/*//draw animated rotated marker..
rotateMarker(mCurrent,-360,mMap);*/
}
});
}
}
else
{
Log.d("ERROR","Cannot get your location");
}
}
private void rotateMarker(final Marker mCurrent, final float i, GoogleMap mMap) {
final Handler handler=new Handler();
final long start= SystemClock.uptimeMillis();
final float startRotation=mCurrent.getRotation();
final long duration=1500;
final Interpolator interpolator=new LinearInterpolator();
handler.post(new Runnable() {
@Override
public void run() {
long elapsed=SystemClock.uptimeMillis()-start;
float t=interpolator.getInterpolation((float)elapsed/duration);
float rot=t*i+(1-t)*startRotation;
mCurrent.setRotation(-rot>180?rot/2:rot);
if(t<1.0)
{
handler.postDelayed(this,16);
}
}
});
}
private void startLocationUpdate() {
if(ActivityCompat.checkSelfPermission(this,Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED &&
ActivityCompat.checkSelfPermission(this,Manifest.permission.ACCESS_FINE_LOCATION) !=PackageManager.PERMISSION_GRANTED)
{
return;
}
LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient,mLocationRequest, this);
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
mMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
mMap.setTrafficEnabled(false);
mMap.setIndoorEnabled(false);
mMap.setBuildingsEnabled(false);
mMap.getUiSettings().setZoomControlsEnabled(true);
}
@Override
public void onLocationChanged(Location location) {
lastLocation=location;
displayLocation();
}
@Override
public void onConnected(@Nullable Bundle bundle) {
displayLocation();
startLocationUpdate();
}
@Override
public void onConnectionSuspended(int i) {
mGoogleApiClient.connect();
}
@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
}
}
Заяц - мой Android Манифест
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.ubarclone">
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="com.google.android.providers.gsf.permisson.READ_GSERVICES" />
<application
android:allowBackup="true"
android:appComponentFactory="whateverString"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:replace="android:appComponentFactory">
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="@string/google_maps_key" />
<activity
android:name=".Welcome"
android:label="@string/title_activity_welcome"></activity>
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Скриншот моей проблемы:
Когда я нажимаю на панель поиска вверху, появляется это сообщение об ошибке: