Unable to add marker on map in Android

守給你的承諾、 提交于 2019-12-31 03:18:07

问题


I am getting this exception while starting the mapActivity.

GooglePlayServicesUtil: Google Play services out of date. Requires 8298000 but found 6599036

and App Crashes at following line.

final Marker marker = mMap.addMarker(new MarkerOptions().position(location);

Note: App is working fine on 4.3 and 5.0.1 version but facing this problem in 4.4.2. Any solution?

Thanks


回答1:


This is a runtime error that occurs when the device does not have at least the same version of Google Play Services that your app is compiled with.

You should have code in your app that prompts the user to upgrade Google Play Services if they don't have the minimum version required by your app. The old, now deprecated way was to use GooglePlayServicesUtil:

status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
if (status != ConnectionResult.SUCCESS) {
    if (GooglePlayServicesUtil.isUserRecoverableError(status)) {
        GooglePlayServicesUtil.getErrorDialog(status, this,
                100).show();
    } 
}

The new way is to use the new GoogleApiAvailability class, code from this answer:

private boolean checkPlayServices() {
    GoogleApiAvailability googleAPI = GoogleApiAvailability.getInstance();
    int result = googleAPI.isGooglePlayServicesAvailable(this);
    if(result != ConnectionResult.SUCCESS) {
        if(googleAPI.isUserResolvableError(result)) {
            googleAPI.getErrorDialog(this, result,
                    PLAY_SERVICES_RESOLUTION_REQUEST).show();
        }

        return false;
    }

    return true;
}



回答2:


Google Play services out of date. Requires 8298000 but found 6599036

Update packages in Tools > Android > SDK Manager and then check all the packages in Extras that have an update available.

Please use updated version

dependencies {
        compile 'com.google.android.gms:play-services:8.4.0'
        // or compile 'com.google.android.gms:play-services-wearable:7.8.0'
    }


来源:https://stackoverflow.com/questions/35148225/unable-to-add-marker-on-map-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!