mapView показывает только логотип Google - PullRequest
0 голосов
/ 30 мая 2019

Я пытаюсь показать вид карты в своей активности, и он не показывает ничего, только логотип Google

Я попытался изменить ключ API и создать другие ключи, но он не работает, и я уверен, что я включилслужбы API, я скопировал код из примеров Google для карт, так что я думаю, что мой класс Java хорошо подходит, я думаю, что это что-то в ключах API Google, но я создал его несколько раз и создал новый проект, и не работает

XML-файл

   <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="50"
        android:id="@+id/map_container">

        <com.google.android.gms.maps.MapView

          xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/user_list_map" />

    </RelativeLayout>

Java-класс

public class UserListFragment extends Fragment implements 
OnMapReadyCallback {

private static final String TAG = "UserListFragment";

//widgets
private RecyclerView mUserListRecyclerView;
private MapView mMapView;


//vars
private ArrayList<User> mUserList = new ArrayList<>();
private UserRecyclerAdapter mUserRecyclerAdapter;


public static UserListFragment newInstance() {
    return new UserListFragment();
}

@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (getArguments() != null) { 
        mUserList = 

  getArguments()
 .getParcelableArrayList(getString(R.string.intent_user_ls
t));
    }
}

@Nullable
@Override
   public View onCreateView(@NonNull LayoutInflater inflater, @Nullable 
  ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_user_list, 
   container, false);
    mUserListRecyclerView = 
   view.findViewById(R.id.user_list_recycler_view);
    mMapView = (MapView) view.findViewById(R.id.user_list_map);
    initUserListRecyclerView();
    initGoogleMap(savedInstanceState);

    return view;

}

private void initGoogleMap(Bundle savedInstanceState) {

    Bundle mapViewBundle = null;
    if (savedInstanceState != null) {
        mapViewBundle = 
  savedInstanceState.getBundle(MAPVIEW_BUNDLE_KEY);
    }
    mMapView.onCreate(mapViewBundle);

    mMapView.getMapAsync(this);

}

private void initUserListRecyclerView() {
    mUserRecyclerAdapter = new UserRecyclerAdapter(mUserList);
    mUserListRecyclerView.setAdapter(mUserRecyclerAdapter);
    mUserListRecyclerView.setLayoutManager(new  
LinearLayoutManager(getActivity()));
}

@Override
public void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);

    Bundle mapViewBundle = outState.getBundle(MAPVIEW_BUNDLE_KEY);
    if (mapViewBundle == null) {
        mapViewBundle = new Bundle();
        outState.putBundle(MAPVIEW_BUNDLE_KEY, mapViewBundle);
    }

    mMapView.onSaveInstanceState(mapViewBundle);
}

@Override
public void onResume() {
    super.onResume();
    mMapView.onResume();
}

@Override
public void onStart() {
    super.onStart();
    mMapView.onStart();
}

@Override
public void onStop() {
    super.onStop();
    mMapView.onStop();
}

@Override
 public void onMapReady(GoogleMap map) {
    map.addMarker(new MarkerOptions().position(new LatLng(0, 
    0)).title("Marker"));

    if (ActivityCompat.checkSelfPermission(getActivity(), 
  Manifest.permission.ACCESS_FINE_LOCATION) != 
 PackageManager.PERMISSION_GRANTED && 
 ActivityCompat.checkSelfPermission(getActivity(), 
 Manifest.permission.ACCESS_COARSE_LOCATION) != 
   PackageManager.PERMISSION_GRANTED) {
        return;
    }
    map.setMyLocationEnabled(true);

}

@Override
public void onPause() {
    mMapView.onPause();
    super.onPause();
}

@Override
public void onDestroy() {
    mMapView.onDestroy();
    super.onDestroy();
}

@Override
public void onLowMemory() {
    super.onLowMemory();
    mMapView.onLowMemory();
}
}

Manifest.xml

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission 
 android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission 
android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

<uses-feature
    android:glEsVersion="0x00020000"
    android:required="true"/>


<application
    android:name=".UserClient"
    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=".ui.MainActivity"></activity>
    <activity android:name=".ui.LoginActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

    <meta-data
        android:name="com.google.android.geo.API_KEY"
        android:value="@string/google_api_key" />

    <meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />

    <uses-library
        android:name="org.apache.http.legacy"
        android:required="false" />



</application>

приложение Gradle #

   apply plugin: 'com.android.application'

 android {
compileSdkVersion 27
   defaultConfig {
    applicationId "com.codingwithmitch.googlemaps2018"
    minSdkVersion 15
    targetSdkVersion 27
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner 
 "android.support.test.runner.AndroidJUnitRunner"
    multiDexEnabled true
 }
 buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard- 
 android.txt'), 'proguard-rules.pro'
    }
}
}

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint- 
layout:1.1.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 
'com.android.support.test.espresso:espresso-core:3.0.2'
//Android Support Design Library
implementation 'com.android.support:design:27.1.1'
//RecyclerView
implementation 'com.android.support:recyclerview-v7:27.1.1'
// Support multidex
implementation 'com.android.support:multidex:1.0.3'
// Firebase Core
implementation 'com.google.firebase:firebase-core:16.0.1'
//Firebase Authentication
implementation 'com.google.firebase:firebase-auth:16.0.2'
// Firestore Firestore
implementation 'com.google.firebase:firebase-firestore:17.0.4'

// glide
implementation 'com.github.bumptech.glide:glide:4.8.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0'

// google locations and maps
implementation 'com.google.android.gms:play-services- 
location:15.0.1'
implementation 'com.google.android.gms:play-services-maps:15.0.1'

// Circle ImageView
implementation 'de.hdodenhof:circleimageview:2.2.0'
implementation 'com.android.support:design:27.0.0' 
}
apply plugin: 'com.google.gms.google-services'
...