无法在模拟器中执行map API

时间:2013-10-17 06:44:11

标签: java android google-maps

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

enter image description here

模拟器我得到如下

enter image description here


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

如果是这样,有任何替代方法可以让我的程序在MAP的模拟器中执行

2 个答案:

答案 0 :(得分:2)

在模拟器中使用Play服务真是太痛苦了。我从来没有机会让它发挥作用(因为我发现了另一种选择)

我建议您下载并安装Genymotion

它使用VirtualBox虚拟化超快的Android设备,并支持Google Play服务。

祝你好运!

答案 1 :(得分:1)

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

  1. 制作项目的apk
  2. 安装或推送apk到模拟器然后运行该apk - 它将工作。:)