3

私はアンドロイドマップAPI v2を初めて使用しています。3 つの異なるアクティビティ (一部のユーザー アクション) でマップを 1 つずつロードしようとしています。マップは 1 つのアクティビティで正常に読み込まれますが、ズーム ボタンのみでグレーのボックスのみが表示されます。

以下は XML レイアウト (map_view.xml) で、include タグを使用して 3 つの異なるレイアウトに含めています。

<?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>

以下は、1 つのアクティビティでマップを適切にロードするコードです。しかし、他の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);
}

マップの読み込みが適切: ここに画像の説明を入力

正しくロードされていません: ここに画像の説明を入力

4

2 に答える 2

2

この問題のいくつかの代替案を見つけました。あなたのコードは問題ないようです。コードやインクルード タグに問題はありません。主な問題はタブです。アクティビティにロードしてタブで作業していない場所では、マップは正常に機能していると思います。したがって、ビューページャーを使用するか、独自のコントロールを作成してタブとして表示することをお勧めします。マップはこのように機能します。

于 2013-08-28T12:55:54.060 に答える