【问题标题】:MapView shows blank map inside a fragment (Android MAP API V2)MapView 在片段内显示空白地图(Android MAP API V2)
【发布时间】:2015-09-03 11:08:12
【问题描述】:

我目前正在开发一个与谷歌地图集成的应用程序。然而它并没有像我预期的那样运行。它什么也没有显示,只是一个空白的灰色屏幕。

我检查了我的 adb 和 grep Auth 授权似乎没有任何错误。这意味着它消除了错误的可能性API_KEY.

我想知道我没有看到的可能性是什么。我希望在这里找到一些见解..

我的清单

<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_WIFI_STATE" />

<uses-feature
        android:glEsVersion="0x00020000"
        android:required="true"/>
 <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="[Removed]"/>

我的摇篮

compile 'com.google.android.gms:play-services:7.8.0'

我的片段 XML

<com.google.android.gms.maps.MapView
        android:id="@+id/map"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

我的片段

public class CurrentLocationFragment extends Fragment implements OnMapReadyCallback {

private MapView mapView;
private GoogleMap map;

@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_current_location, null);
        FragmentManager fm = getChildFragmentManager();
        mapView = (MapView) view.findViewById(R.id.map);
        mapView.onCreate(savedInstanceState);

        map = mapView.getMap();
        map.getUiSettings().setMyLocationButtonEnabled(false);
        map.setMyLocationEnabled(true);

        //initialize the map
        try {
            MapsInitializer.initialize(this.getActivity());
        } catch (Throwable e) {
            e.printStackTrace();
        }

        //animate the camera
        CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(new LatLng(43.1, -87.9), 10);
        map.animateCamera(cameraUpdate);

        return view;

    }

任何见解都会非常受欢迎!谢谢..

【问题讨论】:

标签: java android google-maps google-maps-api-2


【解决方案1】:

您使用的是 Android Studio 吗?你可以默认创建一个Map App,太简单了,以后你可以更改MainActivity并放入Second或Third Activity,

按照此步骤创建您的应用HERE

【讨论】:

  • 我查过了,还是一样。 Logcat 终于向我表明,我在“console.google.com”中的 SH1 指纹与我的 debug.keystore 不匹配。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-02-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-07-18
  • 1970-01-01
相关资源
最近更新 更多