【问题标题】:android Map works only in launch activityandroid Map 仅在启动活动中有效
【发布时间】:2015-11-16 07:57:36
【问题描述】:

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

我正在使用

Android Studio 、Google Map V 2、Google play services 7.5.0 并完成了其他事情,例如使用 SHA1 创建 api 密钥等

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

如果我将 TestMapAct 作为我的启动器活动,则地图可以工作 当我在我的启动活动之后调用它时,地图可以工作。 如果我这样调用启动活动 -> 登录活动 -> 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

请帮帮我

【问题讨论】:

  • 你能告诉我清单中的活动吗?你在 manifest.xml 中声明了吗
  • 是的,我当然已经在清单中声明了该活动
  • 我建议 3 件事:将 Play Services 更新到最新的 8.3.0,使用最新的支持 Activity 类 AppCompatActivity 并使用 implements OnMapReadyCallback 在地图准备好使用时获取回调。

标签: android dictionary


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-22
    • 1970-01-01
    • 2015-05-05
    • 2023-03-04
    • 1970-01-01
    • 2017-11-04
    相关资源
    最近更新 更多