android Map仅适用于启动活动

时间:2015-11-16 07:57:36

标签: android dictionary

我尝试了很多,但仍然没有解释/解决方案,为什么地图不是正在加载

我正在使用

Android Studio,Google Map V 2,Google Play服务7.5.0以及使用SHA1等创建api密钥等其他功能

我有一个名为TestMapAct.class的活动,其中包含在应用程序中显示地图所需的代码。

如果我将TestMapAct作为我的启动器活动,则可以使用Map 当我在我的启动活动之后调用它时,地图有效。 如果我像这个启动活动那样调用地图,那么地图就不起作用了 - >登录活动 - > TestMapAct

这是我的TestMapAct类

    package com.propstack.propstack.activities;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;

import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
import com.propstack.propstack.R;

/**
 * Created by propstack on 06-11-2015.
 */
public class TestMapAct extends FragmentActivity {

    private static GoogleMap mMap;
    private static Double latitude, longitude;

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

        latitude = 26.78;
        longitude = 72.56;

        setUpMapIfNeeded();
    }

    public void setUpMapIfNeeded() {
        // 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.location_map)).getMap();


//            mMap = ((SupportMapFragment) ProfileActivity.fragmentManager
//                    .findFragmentById(R.id.location_map)).getMap();
            // Check if we were successful in obtaining the map.
            if (mMap != null)
                setUpMap();
        }
    }

    private static void setUpMap() {
        // For showing a move to my loction button
        mMap.setMyLocationEnabled(true);
        // For dropping a marker at a point on the Map
        mMap.addMarker(new MarkerOptions().position(new LatLng(latitude, longitude)).title("My Home").snippet("Home Address"));
        // For zooming automatically to the Dropped PIN Location
        mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(latitude,
                longitude), 12.0f));
    }
}

对应的XML代码: -

<?xml version="1.0" encoding="utf-8"?>
        <fragment xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/location_map"
        class="com.google.android.gms.maps.SupportMapFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

清单详情

    <permission
        android:name="com.propstack.propstack.permission.MAPS_RECEIVE"
        android:protectionLevel="signature" />

    <uses-permission android:name="com.propstack.propstack.permission.MAPS_RECEIVE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />

    <!-- Required OpenGL ES 2.0. for Maps V2 -->
    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true" />

        <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="Key goes here" />
        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />

当地图未显示时记录猫:

ResourcesManager﹕ Asset path '/system/framework/com.android.media.remotedisplay.jar' does not exist or contains no resources.

ResourcesManager﹕ Asset path '/system/framework/com.android.location.provider.jar' does not exist or contains no resources.

ContextImpl﹕ Failed to ensure directory: /storage/sdcard1/Android/data/com.propstack.propstack/cache

请帮帮我

1 个答案:

答案 0 :(得分:0)

如果您的应用启用了 SSL 固定,请将来自此域 clients4.google.com 的服务器证书添加到您的 SSLSocketFactory 密钥库,然后使用 验证主机名>主机名验证器。这就是我如何用类似的行为解决我的问题。