由于Google Play服务,Google地图无法展示

时间:2015-05-08 00:18:38

标签: android google-play-services

我在我的应用中使用Google地图

我现在正在做测试,问题是地图总是显示为灰色屏幕(没有地图显示)

我尝试了不同的设备,不同的机器人仍然是相同的

我知道必须安装Google Play服务。

我添加了此代码,以确保用户在未安装Google Play服务时收到通知,但没有通知显示的内容。

@Override
protected void onResume() {
    super.onResume();
    if (checkPlayServices()) {
        // Then we're good to go!
    }
    isGpsEnabled(getApplicationContext());
}

public static boolean isGpsEnabled(Context context) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
        String providers = Settings.Secure.getString(context.getContentResolver(),
                Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
        if (TextUtils.isEmpty(providers)) {
            return false;
        }
        return providers.contains(LocationManager.GPS_PROVIDER);
    } else {
        final int locationMode;
        try {
            locationMode = Settings.Secure.getInt(context.getContentResolver(),
                    Settings.Secure.LOCATION_MODE);
        } catch (Settings.SettingNotFoundException e) {
            e.printStackTrace();
            return false;
        }
        switch (locationMode) {

            case Settings.Secure.LOCATION_MODE_HIGH_ACCURACY:
            case Settings.Secure.LOCATION_MODE_SENSORS_ONLY:
                return true;
            case Settings.Secure.LOCATION_MODE_BATTERY_SAVING:
            case Settings.Secure.LOCATION_MODE_OFF:
            default:
                return false;
        }
    }
}

private boolean checkPlayServices() {
    int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
    if (status != ConnectionResult.SUCCESS) {
        if (GooglePlayServicesUtil.isUserRecoverableError(status)) {
            showErrorDialog(status);
        } else {
            Toast.makeText(this, "This device is not supported.",
                    Toast.LENGTH_LONG).show();
            finish();
        }
        return false;
    }
    return true;
}

void showErrorDialog(int code) {
    GooglePlayServicesUtil.getErrorDialog(code, this,
            REQUEST_CODE_RECOVER_PLAY_SERVICES).show();
}
static final int REQUEST_CODE_RECOVER_PLAY_SERVICES = 1001;

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    switch (requestCode) {
        case REQUEST_CODE_RECOVER_PLAY_SERVICES:
            if (resultCode == RESULT_CANCELED) {
                Toast.makeText(this, "Google Play Services must be installed.",
                        Toast.LENGTH_SHORT).show();
                finish();
            }
            return;
    }
    super.onActivityResult(requestCode, resultCode, data);
}

这是设置地图的代码

private void setUpMapIfNeeded(String result) {
  //  mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)) .getMap();

    // Do a null check to confirm that we have not already instantiated the map.
    if (mMap == null) {
        // Try to obtain the map from the SupportMapFragment.
        mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
        // Check if we were successful in obtaining the map.
        if (mMap != null) {
            setUpMap(result);


            FocusMap();
            mMap.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {

                @Override
                public void onInfoWindowClick(Marker marker) {
                    Intent addNew = new Intent(MapsActivity.this, ItemDetail.class);
                    String Header = marker.getTitle();
                    int Pos = Header.indexOf(":");
                    String siKey = Header.substring(0, Pos);
                    addNew.putExtra("iKey", siKey);
                    startActivity(addNew);
                }
            });

        }
    }
}

,这是来自gradle.build

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.0.0'
    //compile 'com.google.android.gms:play-services:7.0.0'
    compile 'com.google.android.gms:play-services:7.3.0'
}

我甚至试图直接从Play商店下载Google Play服务,但却无法在Play商店中找到它!我找到了Google Play游戏和其他应用,但没有找到Google Play服务。

我觉得我错过了什么,但不确定是什么。

任何人都可以帮助我吗?

0 个答案:

没有答案