我想在android模拟器中显示地图。为此,我安装了google play服务并将其导入到工作区中,并在我的项目中引用它们。但我运行的应用程序显示,谷歌游戏服务不在你的手机。我不明白为什么会这样。我在这里附上完整的代码。
这是我的清单文件:

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

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

    <permission
        android:name="com.example.map.permission.MAPS_RECEIVE"
        android:protectionLevel="signature" />
    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true" />
     <uses-permission android:name="com.example.map.permission.MAPS_RECEIVE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <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.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.map.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>

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

</manifest>

main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >



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

</RelativeLayout>

.java file is here

package com.example.map;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;

public class MainActivity extends Activity
{



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

    }
![enter image description here][1]
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

}

模拟器映像
你能告诉我为什么会这样吗?它真的帮助了我。

最佳答案

要点1。如果您正在开发API级别8的应用程序,请使用下面的代码。

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

参阅MapFragment
仅当目标是API12及更高版本时才使用此类。否则,请使用supportMapFragment。
要点2。用片段而不是活动来扩展你的课程
私人谷歌地图;
    public void loadGoogleMap(){
        if(googleMap==null){
              // Getting Google Play availability status
              int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(context);
              // Showing status
              if(status!=ConnectionResult.SUCCESS){ // Google Play Services are not available
                  int requestCode = 10;
                  Dialog dialog = GooglePlayServicesUtil.getErrorDialog(status, (Activity)context, requestCode);
                  dialog.show();
              }else{
                // Getting reference to the SupportMapFragment of activity_main.xml
                  SupportMapFragment fm = (SupportMapFragment) this.YOUR_CLASS_NAME.getSupportFragmentManager()
                        .findFragmentById(R.id.my_comm_nearme_map);

                  // Getting GoogleMap object from the fragment
                  googleMap = fm.getMap();

                  //setting map type
                  googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);

                  UiSettings uiSettings = googleMap.getUiSettings();
                  uiSettings.setCompassEnabled(false);
                  uiSettings.setZoomControlsEnabled(true);
                  uiSettings.setMyLocationButtonEnabled(false);
              }
        }
    }

要点3。
But i run application it shows Goolgle play services in not in Your phone.

安卓需要Google Play services才能运行地图。你可以从市场上下载,再试一次,地图就可以了。
如果在安装Google Play services时出错,则说明您的设备不兼容。

08-25 13:51
查看更多