35

私はアンドロイドを学ぼうとしていますが、Google Maps API V.2 の使用方法に関する指示に従っていると、今では動作するようになりました。ただし、 developers.google.comにあるマップの初期状態を構成する方法に関する説明では、xml ファイルで定義された名前空間 (この場合は「マップ」) が提案されています。

以下の xml コードは、「予期しない名前空間プレフィックス "マップ"」というエラーを med に与えます。フラグメント タグ内でxmlns:mapを定義しようとすると、同じエラーが発生しましたが、"xmlns" が含まれていました。

ここで明らかに基本的な xml の知識が欠けています。誰か助けてもらえますか?

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"        
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:map="http://schemas.android.com/apk/res-auto"      <!-- Definition -->
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <fragment 
        android:id="@+id/map"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        class="com.google.android.gms.maps.SupportMapFragment"
        map:cameraBearing="112.5"/>                            <!-- PROBLEM -->

</RelativeLayout>
4

9 に答える 9

26

私もこの問題を抱えていました。Project/Clean を実行したところ、エラーは解消され、正常に動作するようになりました。

于 2013-04-20T02:00:33.363 に答える
20

次の 2 つのことを行う必要があります。

最初: https://docs.google.com/document/pub?id=19nQzvKP-CVLd7_VrpwnHfl-AE9fjbJySowONZZtNHzw

Google Play Services への依存関係をプロジェクトに追加します

Project -> Properties -> Android -> Library, Add -> google-play-services_lib

2 番目: https://developers.google.com/maps/documentation/android/intro

を選択Project > Propertiesし、 を選択しJava Build Pathて、 に移動しLibrariesます。を選択Add External Jarsし、次の jar ファイルを含めて、[OK] をクリックします。

<android-sdk-folder>/extras/android/compatibility/v4/android-support-v4.jar

これで、私のプロジェクトにはエラーが表示されなくなりました:)

于 2013-04-10T10:54:58.787 に答える
19

今日も同じ問題があります。昨夜SDKをアップグレードしましたが、以前はこの問題は発生していませんでした。Android Map V2サンプルデモプロジェクトもロードしましたが、今日、「multimap_demo.xml」ファイルに「タグフラグメントに予期しない名前空間プレフィックス「map」が見つかりました」というエラーが表示されます。提案されたxmlインクルードを適用しましたが、再び機能しています。+1を与えますが、信用を得ません。

更新:この問題を忘れて、今日コードを作り直し、インクルードを削除しました。もちろん、エラーが戻ってきました。これを見つけて、フラグメントスタンザのレイアウトに追加しました。

tools:ignore="MissingPrefix"

少なくとも問題を覆い隠しているようです。

更新:このバグは、AndroidLintToolのバグが原因で発生したようです。問題https://code.google.com/p/gmaps-api-issues/issues/detail?id=5002を参照してください

于 2013-03-07T19:16:15.413 に答える
13

Java コードではなく、レイアウト ファイルですべての設定を続行できる別の回避策があります。エラーはレイアウト ファイル内のSupportMapFragmentの子である場合にのみ発生するように見えるため、要素を独自のレイアウト ファイルにViewGroup抽出し、それを目的のより大きなレイアウトに含めることができます。<fragment>

たとえば、これを行おうとしているとします。

my_awesome_layout.xml

...
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"        
    xmlns:map="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <fragment 
        android:id="@+id/map"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        class="com.google.android.gms.maps.SupportMapFragment"
        map:cameraBearing="112.5"/>

</RelativeLayout>

代わりに、次のように分割できます。

include_map_fragment.xml

<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:map="http://scheams.android.com/apk/res-auto"
    android:id="@+id/map"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    class="com.google.android.gms.maps.SupportMapFragment"
    map:cameraBearing="112.5"/>

my_awesome_layout.xml

...
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"        
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <include 
        android:id="@+id/map"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        layout="@layout/include_map_fragment" />

</RelativeLayout>
于 2013-03-07T14:49:27.387 に答える
4

まあ、これは実際には名前空間の問題の解決策ではありませんが、おそらくこれが役立つかもしれません.

私は XML ソリューションをまったく知らないので、プログラムで実行しました。

mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
mMap.setTrafficEnabled(true);
setupMapView();

private void setupMapView(){
 UiSettings settings = mMap.getUiSettings();        
 mMap.animateCamera(CameraUpdateFactory.newCameraPosition(
  new CameraPosition(new LatLng(50.0, 10.5), 
  13.5f, 30f, 112.5f))); // zoom, tilt, bearing
 mMap.setTrafficEnabled(true);
 settings.setAllGesturesEnabled(true);
 settings.setCompassEnabled(true);
 settings.setMyLocationButtonEnabled(true);
 settings.setRotateGesturesEnabled(true);
 settings.setScrollGesturesEnabled(true);
 settings.setTiltGesturesEnabled(true);
 settings.setZoomControlsEnabled(true);
 settings.setZoomGesturesEnabled(true);
}

そのため、Google マップはデフォルトで初期化されますが、その直後にコードからパラメーターを取得します。

于 2013-02-27T15:46:47.413 に答える
3

私はまったく同じ問題を抱えています。提供された例

<fragment xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:map="http://schemas.android.com/apk/res-auto"
  android:id="@+id/map"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  class="com.google.android.gms.maps.SupportMapFragment"
  map:cameraBearing="112.5"
  map:cameraTargetLat="-33.796923"
  map:cameraTargetLng="150.922433"
  map:cameraTilt="30"
  map:cameraZoom="13"
  map:mapType="normal"
  map:uiCompass="false"
  map:uiRotateGestures="true"
  map:uiScrollGestures="false"
  map:uiTiltGestures="true"
  map:uiZoomControls="false"
  map:uiZoomGestures="true"/>

正常に動作しますが、親要素に追加しようとすると、xmlnsの受け入れを拒否します。xmlns宣言を最上位の要素に移動しても、フラグメント内のマッププレフィックスを受け入れることを拒否します。

Unexpected namespace prefix "map" found for tag fragment

ここで、SupportMapFragmentを拡張し、次のようなカスタムビューを使用する場合:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:map="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="5dp">

    <com.google.android.gms.maps.MapView
        android:id="@+id/map_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent" 
        map:cameraBearing="0" 
        map:cameraTargetLat="54.25"
        map:cameraTargetLng="-4.56"
        map:cameraTilt="30"
        map:cameraZoom="5.6"
        map:mapType="normal"
        map:uiCompass="true"
        map:uiRotateGestures="true"
        map:uiScrollGestures="true"
        map:uiTiltGestures="true"
        map:uiZoomControls="false"
        map:uiZoomGestures="true">

    </com.google.android.gms.maps.MapView>

</LinearLayout>

...その後、文句を言わず、結果のマップは正しいです。しかし、このサブクラス化を行う方法の適切な例がないため、さらに問題が発生する私にとっては、 onCreateViewをオーバーライドする以上のことを行う必要があり、その後マップに対して何かをしようとすると、次のようになります。

java.lang.IllegalStateException: Map size should not be 0. Most likely, layout has not yet occured for the map view.

...地図が表示されてから30秒待っても(最初の読み込みのみ)

于 2013-02-23T10:59:52.363 に答える
1

で行っているように、タグに XML コメントを入れることはできないと思います<!-- Definition -->。それを削除しても、問題は引き続き発生しますか?

于 2013-02-22T22:42:19.690 に答える
0

明らかに、これは誤解を招くリント チェック エラーです。Eclipseの問題ビューで、エラーのある行を右クリックし、クイックフィックスオプションを選択して、プロジェクトのチェックを無視するなどを選択すると、それを削除できます。

エラーが解消され、プロジェクトがビルドされ、アプリが完全に正常に動作します。

于 2014-03-03T18:00:16.170 に答える