我是新的android地圖api v2。我正在嘗試在3個不同的活動(某些用戶操作)中逐個加載地圖。地圖在1個活動中加載正常,但只能用縮放按鈕僅顯示灰色框。Android地圖V2地圖加載一個活動,但不在其他兩個
以下是XML佈局(map_view.xml)我使用include標籤在三種不同的佈局中包括。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="10dp" >
<fragment
android:id="@+id/mapLocationDetail"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.MapFragment" />
<ImageView
android:id="@+id/transparent_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@android:color/transparent" />
<Button
android:id="@+id/btnRefresh"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="10dp"
android:layout_marginRight="10dp"
android:background="@drawable/btn_green_small"
android:text="Direction"
android:textColor="@color/white" />
</RelativeLayout>
以下是加載地圖在適當一個活動的代碼。而不是在其他2
package com.nthreads.out2b.activity.places;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
import com.nthreads.out2b.Out2B;
import com.nthreads.out2b.R;
public class LocationDetailActivity extends Out2B {
static final LatLng HAMBURG = new LatLng(53.558, 9.927);
static final LatLng KIEL = new LatLng(53.551, 9.993);
private GoogleMap map;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_location_detail);
map = ((MapFragment) getFragmentManager().findFragmentById(R.id.mapLocationDetail))
.getMap();
Marker hamburg = map.addMarker(new MarkerOptions().position(HAMBURG)
.title("Hamburg"));
Marker kiel = map.addMarker(new MarkerOptions()
.position(KIEL)
.title("Kiel")
.snippet("Kiel is cool")
.icon(BitmapDescriptorFactory
.fromResource(R.drawable.map_resturant_marker)));
// Move the camera instantly to hamburg with a zoom of 15.
map.moveCamera(CameraUpdateFactory.newLatLngZoom(HAMBURG, 15));
// Zoom in, animating the camera.
map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);
map.getUiSettings().setZoomControlsEnabled(false);
}
地圖加載正確:
不正確加載:
你給的代碼工作正常,我想。地圖不起作用的Activity的代碼在哪裏? – Nizam