0
我想在我的一个活动中显示一个非常基本的MapView,但是,我的MapView永远是空白的,永远不会加载任何地图。所述MapView仅仅是具有其他元素的活动的200px高度。我没有从向导创建一个Map活动。Android谷歌地图基本地图
我的表现有:
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<!--
The API key for Google Maps-based APIs.
-->
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="my real code" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
我的build.gradle具有依赖性:
compile 'com.google.android.gms:play-services-maps:10.2.1'
我AndroidStudio有GOOGLEPLAY包。你知道我错过了什么吗?
这是我的MapView XML代码:
<LinearLayout
android:id="@+id/geolocationLinearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/textView4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="Geolocation"
android:textStyle="bold|italic" />
<com.google.android.gms.maps.MapView
android:id="@+id/mapView"
android:layout_width="match_parent"
android:layout_height="200dp" />
</LinearLayout>
这是我的活动Java类映射声明和装载:
声明:
MapView mapView;
GoogleMap map;
static final LatLng HAMBURG = new LatLng(53.558, 9.927);
内OnCreateView:
mapView = (MapView) view.findViewById(R.id.mapView);
mapView.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(GoogleMap googleMap) {
map = googleMap;
map.moveCamera(CameraUpdateFactory.newLatLngZoom(HAMBURG, 15));
}
});
mapView.onCreate(...)在哪里? – Blackkara
我加了mapView.onCreate(mBundle);现在我看到底部左侧带有Google徽标的mapView,但是地图未加载......我需要编写其他任何代码吗? – user1060551
如果地图空白,常见问题是API密钥错误 –