Google地图在一项活动中不起作用,但在另一项活动中起作用

时间:2017-12-28 06:22:29

标签: android google-maps

我创建了一个跟踪用户位置的应用,并在Google地图片段上绘制折线以显示其路径。我将latlng信息存储在我的SQLite数据库中,以便我可以在另一个活动中再次绘制路径以向用户显示其路径。

我的问题是谷歌地图在我跟踪位置的活动中运行良好,但是查看活动中的谷歌地图片段是空白的,但它仍然显示标记。我已经尝试制作一个新的API密钥,但是没有用。在谷歌搜索此问题,我只能找到无法使单个地图片段工作的人,问题通常是API密钥。我已经确定了latlng点也是正确的。

地图片段无效的类:

package com.example.bocks.mdplab4merge;

public class ViewingActivity extends FragmentActivity implements OnMapReadyCallback {

private GoogleMap mMap;
private List<LatLng> points;
Polyline line;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_viewing);

    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
            .findFragmentById(R.id.map2);
    mapFragment.getMapAsync(this);

    points = new ArrayList<LatLng>();

    Bundle bundle = getIntent().getExtras();

    points = PolyUtil.decode(bundle.getString("LOCATIONS"));

}

@Override
public void onMapReady(GoogleMap googleMap) {
    mMap = googleMap;

    //mMap.clear();
    PolylineOptions options = new PolylineOptions().width(5).color(Color.BLUE).geodesic(true);
    options.addAll(points);

    LatLng start = new LatLng(points.get(0).latitude, points.get(0).longitude);
    LatLng end = new LatLng(points.get(points.size() - 1).latitude, points.get(points.size() - 1).latitude);

    Marker startMarker = mMap.addMarker(new MarkerOptions().position(new LatLng(0, 0)).title("Start Position").icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED)));
    startMarker.setPosition(start);

    Marker endMarker = mMap.addMarker(new MarkerOptions().position(new LatLng(0, 0)).title("End Position").icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE)));
    endMarker.setPosition(end);

    mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(end, 15));
    Log.d("g53mdp", "Camera Moved");

    line = mMap.addPolyline(options);
}

}

这是XML:

<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/map2"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.bocks.mdplab4merge.ViewingActivity" />

我的Android清单:

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

<uses-permission android:name="android.permission.ACCESS_LOCATION" />
<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" />


<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">
    <meta-data
        android:name="com.google.android.geo.API_KEY"
        android:value="@string/google_maps_key" />

    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

    <provider
        android:name=".ExerciseProvider"
        android:authorities="com.example.bocks.mdplab4merge.ExerciseProvider" />

    <service
        android:name=".TrackingService"
        android:enabled="true"
        android:exported="true" />

    <activity android:name=".ListActivity" />
    <activity android:name=".FilterActivity" />
    <activity
        android:name=".ViewingActivity"
        android:label="@string/title_activity_viewing"></activity>
</application>

---- ---- EDIT 以下是查看活动开始时的logcat:

12-28 01:53:01.347 21376-21376/com.example.bocks.mdplab4merge I/Google Maps Android API: Google Play services client version: 10260000
12-28 01:53:01.352 21376-21376/com.example.bocks.mdplab4merge I/Google Maps Android API: Google Play services package version: 11509470
12-28 01:53:01.666 21376-21425/com.example.bocks.mdplab4merge W/EGL_emulation: eglSurfaceAttrib not implemented
12-28 01:53:01.666 21376-21425/com.example.bocks.mdplab4merge W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xe86eb840, error=EGL_SUCCESS

                                                                            [ 12-28 01:53:01.676 21376:21927 D/         ]
                                                                            HostConnection::get() New Host Connection established 0xd6d55950, tid 21927
12-28 01:53:01.718 21376-21376/com.example.bocks.mdplab4merge D/g53mdp: Camera Moved
12-28 01:53:03.618 21376-21929/com.example.bocks.mdplab4merge W/DynamiteModule: Local module descriptor class for com.google.android.gms.googlecertificates not found.
12-28 01:53:06.546 21376-21929/com.example.bocks.mdplab4merge I/DynamiteModule: Considering local module com.google.android.gms.googlecertificates:0 and remote module com.google.android.gms.googlecertificates:4
12-28 01:53:06.546 21376-21929/com.example.bocks.mdplab4merge I/DynamiteModule: Selected remote version of com.google.android.gms.googlecertificates, version >= 4
12-28 01:53:06.555 21376-21929/com.example.bocks.mdplab4merge W/System: ClassLoader referenced unknown path: /data/data/com.google.android.gms/app_chimera/m/00000001/n/x86

0 个答案:

没有答案