Android Студийные карты не отображаются - PullRequest
1 голос
/ 18 марта 2020

Я дома из-за разногласий с коронавирусом, и поэтому я пытаюсь продолжить учебу. Сейчас у меня проблема Android Studio при создании приложения для карт. Приложение должно найти местоположение по широте и долготе, а также по названию города и определить местоположение с помощью плавающей кнопки. Код работал отлично, когда я добавил код для определения местоположения, карта больше не отображалась. Загружается без ошибок, но карта не работает.

Захват карт

Манифест.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.pt3_googlemaps_filipetto_patricio">

    <!--
         The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
         Google Maps Android API v2, but you must specify either coarse or fine
         location permissions for the 'MyLocation' functionality.
    -->

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

    <application
        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">

        <!--
             The API key for Google Maps-based APIs is defined as a string resource.
             (See the file "res/values/google_maps_api.xml").
             Note that the API key is linked to the encryption key used to sign the APK.
             You need a different API key for each encryption key, including the release key that is used to
             sign the APK for publishing.
             You can define the keys for the debug and release targets in src/debug/ and src/release/.
        -->
        <meta-data
            android:name="com.google.android.geo.API_KEY"
            android:value="AIzaSyAHwtaI8O698ZSeVM8Y4xvjRXxAYi9Kr38" />
        <uses-library android:name="com.google.android.maps" />

        <activity
            android:name=".MapsActivity"
            android:label="@string/title_activity_maps">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

Также прикрепите зависимости.

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'com.google.android.gms:play-services-maps:17.0.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    implementation 'com.google.android.material:material:1.1.0'
    implementation 'com.android.support:design:29.0.0'
}

1 Ответ

0 голосов
/ 18 марта 2020

Я добавил это, когда я нажимал кнопку, чтобы найти свое местоположение и перейти к нему.

 FloatingActionButton myUBICATION = findViewById(R.id.myUBICATION);
        myUBICATION.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                if(mMap != null){
                    mMap.setOnMyLocationClickListener(new GoogleMap.OnMyLocationClickListener() {
                        @Override
                        public void onMyLocationClick(@NonNull Location location) {

                            LatLng GPS = new LatLng(location.getLatitude(), location.getLongitude());
                            mMap.addMarker(new MarkerOptions().position(GPS).title("Marker my ubication"));
                            mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(GPS, 10));
                        }
                    });
                }

            }
        });
...