3

无法在模拟器中执行 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 的模拟器中执行

4

2 回答 2

2

在模拟器中使用 Play Services 真的很痛苦。我从来没有机会让它发挥作用(因为我找到了替代方案)

我建议您下载并安装Genymotion

它使用 VirtualBox 来虚拟化超快的安卓设备和那些支持 Google Play 服务的设备。

祝你好运!

于 2013-10-17T07:10:25.473 回答
1

尝试在模拟器中安装登录 apk,例如:

  1. 为您的项目制作 apk
  2. 将该apk安装或推送到模拟器中,然后运行该apk-它将起作用。:)
于 2013-10-17T07:02:58.500 回答