无法在模拟器中执行MAP API

MainActivity.java

public class MainActivity extends FragmentActivity {

    // Google Map
    private GoogleMap googleMap;

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

        try {
            // Loading map
            initilizeMap();

        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    /**
     * function to load map. If map is not created it will create it for you
     * */
    private void initilizeMap() {
        if (googleMap == null) {



            SupportMapFragment fm = (SupportMapFragment) getSupportFragmentManager()
                    .findFragmentById(R.id.map);
            googleMap = fm.getMap();


            // check if map is created successfully or not
            if (googleMap == null) {
                Toast.makeText(getApplicationContext(),
                        "Sorry! unable to create maps", Toast.LENGTH_SHORT)
                        .show();
            }
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        initilizeMap();
    }

}

清单
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.googlemaps"
    android:versionCode="1"
    android:versionName="1.0" >

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

    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

    <!-- Required to show current location -->
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.googlemaps.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>

        <!-- Goolge Maps API Key -->
       <!-- <meta-data
            android:name="com.example.googlemaps.API_KEY"
            android:value="AIzaSyB_nfzBC625kv_O6GzW-O8l2oLBhqAGCIc" /> -->

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

</manifest>

activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

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

</RelativeLayout>

没有错误..但是日志显示如下
10-17 11:58:50.169: D/dalvikvm(592): DexOpt: couldn't find field Landroid/content/res/Configuration;.smallestScreenWidthDp
10-17 11:58:50.169: W/dalvikvm(592): VFY: unable to resolve instance field 28
10-17 11:58:50.169: D/dalvikvm(592): VFY: replacing opcode 0x52 at 0x0012
10-17 11:58:50.199: W/GooglePlayServicesUtil(592): Google Play Store is missing.
10-17 11:58:50.209: W/GooglePlayServicesUtil(592): Google Play Store is missing.
10-17 11:58:50.209: W/GooglePlayServicesUtil(592): Google Play Store is missing.
10-17 11:58:50.219: W/GooglePlayServicesUtil(592): Google Play Store is missing.
10-17 11:58:50.219: W/GooglePlayServicesUtil(592): Google Play Store is missing.
10-17 11:58:50.259: W/GooglePlayServicesUtil(592): Google Play Store is missing.
10-17 11:58:50.369: W/GooglePlayServicesUtil(592): Google Play Store is missing.
10-17 11:58:50.399: W/GooglePlayServicesUtil(592): Google Play Store is missing.
10-17 11:58:50.459: V/TLINE(592): new: android.text.TextLine@4090edb0
10-17 11:58:50.499: D/dalvikvm(592): GC_CONCURRENT freed 80K, 3% free 9051K/9287K, paused 7ms+5ms
10-17 11:58:50.759: V/TLINE(592): new: android.text.TextLine@408a52c0

我已经添加了Google Play商店

我得到的模拟器如下



无法在模拟器中运行MAP-API

如果是这样,还有其他选择可以使我的程序在MAP的仿真器中执行

最佳答案

在仿真器中使用Play服务确实很痛苦。我从来没有机会使它起作用(因为我找到了替代方法)

我建议您下载并安装Genymotion

它使用VirtualBox虚拟化超快速的android设备,这些设备支持Google Play服务。

祝好运!

关于java - 无法在模拟器中执行Map API,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19419948/

10-10 19:55