1

google mapversion2を使用しています。API鍵を入手し、それらを に配置しmanifestます。一部のデバイスではマップを表示できますが、別のデバイスで同じアプリをコンパイルすると、マップを表示する代わりに空白の画面が表示されます。誰でもこれについて私を案内できますか

    FragmentManager myFragmentManager = getFragmentManager();
    MapFragment myMapFragment = (MapFragment)myFragmentManager.findFragmentById(R.id.map);
    myMap = myMapFragment.getMap();

     if (myMap == null) {
         myMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
                                .getMap();
     }
    myMap.setMapType(GoogleMap.MAP_TYPE_TERRAIN);
    myMap.setMyLocationEnabled(true);
    myMap.setOnMyLocationChangeListener(this);
4

1 に答える 1

0

activity_map.xml

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

MapActivity.java

public class MapActivity extends Activity {

private GoogleMap map;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_map);

    map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
            .getMap();

    //modify below according to your requirement
    map.setMapType(GoogleMap.MAP_TYPE_TERRAIN);
    map.setMyLocationEnabled(true);
    ..
    ..
    ..

マニフェスト ファイルに以下を追加します。

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

  <uses-permission android:name="com.yourpackage.permission.MAPS_RECEIVE" />

 <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-feature
    android:glEsVersion="0x00020000"
    android:required="true" />

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

もちろん、アクティビティ名などの他のマニフェスト パラメーターを使用する必要があります。

次に、Google Play サービス ライブラリをプロジェクトに参照する必要があります。
このリンクに従って、Google Play サービス SDK をインストールします Google Play サービス SDK をインストールします

その後

Your Project--->Right Click-->Properites-->Android-->Add

上記の方法で言及したことを使用して、ワークスペースにインポートする google-play-services sdk を選択します

最後に、Android SDK ターゲットを選択して

Google API バージョン 8

または要件に応じて他の Google API バージョン。

さらに混乱が生じた場合は、次の Android 公式リンクをたどることができます: Google Maps Android API v2

更新されたコード:

下位バージョンで動作させるには:

activity_map.xml

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

MyMapActivity.java

FragmentManager fragmentManager = getSupportFragmentManager();
SupportMapFragment mapFragment =  (SupportMapFragment)
fragmentManager.findFragmentById(R.id.map);
map = mapFragment.getMap();

ありがとう !!

于 2013-06-20T08:28:42.033 に答える