4

私は2.3.3をサポートするAndroidアプリでmaps api v2を使用しており、setMyLocationEnabled(true)を設定しています。もちろん、ジェリービーンでは正常に動作するボタンがありますが、2.3.3では動作しません。

マップの呼び出し方法は次のとおりです。

    private void setUpMapIfNeeded() {
    // Do a null check to confirm that we have not already instantiated the map.
    if (mMap == null) {
        // Try to obtain the map from the SupportMapFragment.
        mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();

        // Check if we were successful in obtaining the map.
        if (mMap != null) {
            setUpMap();
        }
    }
}

private void setUpMap(){
    mMap.setMyLocationEnabled(true);
    if(ttdBranch!=null){
        mMap.addMarker(new MarkerOptions()
        .position(new LatLng(ttdBranch.getLatitude(), ttdBranch.getLongitude()))
        .snippet(getResources().getString(R.string.branch) + "\n" + ttdBranch.getName()));
        LatLng pos = new LatLng(ttdBranch.getLatitude(),ttdBranch.getLongitude());
        mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(pos, 14));
    }
}

ここにマニフェストがあります:

<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17" />

<uses-feature android:glEsVersion="0x00020000" android:required="true"/>

<permission android:name="*******.permission.MAPS_RECEIVE" android:protectionLevel="signature"/>

<uses-permission android:name="*******.permission.MAPS_RECEIVE"/>
<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.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CALL_PHONE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_ttd_petales"
    android:label="@string/app_name"
    android:theme="@style/Holo.Theme.Light" >
    <activity
        android:name="*******.MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <activity android:name="*******.BranchesMapActivity" />
    <activity android:name="*******.BranchDetailActivity"/>


    <meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="*******"/>

電話で位置センサーが有効になっていることを確認しました。Google マップ アプリでは機能しますが、私のアプリでは機能しません。

助けはありますか?

ありがとう。

4

1 に答える 1

1

これを以下で確認してください。

1.「android-support-v4.jar」を含む「libs」フォルダーがプロジェクトに存在するかどうかを確認します。

"android-support-v4.jar" is located in "/extras/android/compatibility/v4/android-support-v4.jar" under your "android-sdk" drectory.

「Google Maps Android API では、MapFragment オブジェクトをサポートするために API レベル 12 以上が必要です。API レベル 12より前のアプリケーションをターゲットにしている場合は、SupportMapFragment クラスを介して同じ機能にアクセスできます。また、Android を含める必要があります。サポート ライブラリ」を参照してください。この Android 開発ガイド (ここをクリック)で説明されています。

2. プロジェクトを実行する前に、プロジェクトのビルド ターゲットを Android xx バージョンではなく「Google API」に設定する必要があります。

Select your project and click Project > Properties > Project Build Target in Eclipse and select any "Google APIs ", and then run your project on your real phone(handset). If you use the emulator, you will get the failed result because the app with the Google Play Service library is not supported in the emulator.

「Google Play サービスは Android エミュレーターではサポートされていません。APIを使用して開発するには、Android フォンやタブレットなどの開発デバイスを提供する必要があります。」この Android 開発ガイド (ここをクリック)で説明されています。

3. 繰り返しになりますが、プロジェクトをテストするために新しい Google Maps API キーを作成する必要はありません。デフォルトで提供されている API キーを使用するだけです。 API コンソール。

4.最後に、最も重要なことは、次のように Google Play サービスを Android ライブラリ プロジェクトとして追加することです。

Select File > Import > Android > Existing Android Code Into Workspace and click Next. Select Browse..., enter /extras/google/google_play_services/libproject/google-play-services_lib, and click Finish.

私のコメントがお役に立てば幸いです。

于 2013-01-24T02:14:13.017 に答える