OGeek|极客世界-中国程序员成长平台

标题: android - 我们如何在模拟器上测试 Google Map API v2 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-9 06:50
标题: android - 我们如何在模拟器上测试 Google Map API v2

我使用 v2 Version 实现了 Google Map。我在真实设备上测试了应用程序。它工作正常,但我也想在模拟器上测试它。我该怎么做?

这是我的 manifest.xml

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

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

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

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


    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

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

    <uses-feature android:glEsVersion="0x00020000"
         android:required="true"/>




    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >


        <activity
            android:name="com.example.demogooglemapv2.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="AIzaSyB2jvxyj-WbkYc1Y1WR9Sc1E1W22QywA_k"
            />
    </application>

</manifest>

这是我的 activity_main.xml

<LinearLayout 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 
         class="com.google.android.gms.maps.SupportMapFragment"
        android:id="@+id/map"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        />



</LinearLayout>

这是我的 mainActivity.java

package com.example.demogooglemapv2;

import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;

import android.os.Bundle;
import android.app.Activity;

import android.support.v4.app.FragmentActivity;
import android.util.Log;
import android.view.Menu;
import android.widget.Toast;

public class MainActivity extends FragmentActivity{

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

        int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());

          if (resultCode == ConnectionResult.SUCCESS){
           Toast.makeText(getApplicationContext(), 
             "isGooglePlayServicesAvailable SUCCESS", 
             Toast.LENGTH_LONG).show();
          }else{

          }




    }

    @Override
    protected void onResume() {
        // TODO Auto-generated method stub
        super.onResume();

        int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());

          if (resultCode == ConnectionResult.SUCCESS){
           Toast.makeText(getApplicationContext(), 
             "isGooglePlayServicesAvailable SUCCESS", 
             Toast.LENGTH_LONG).show();

           Log.v(">>>>>>>>>>>>>.", "successs");
          }else{

          }
    }

    @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;
    }

}



Best Answer-推荐答案


这个问题我也纠结了很久。我没有一台Android设备可以使用,所以我必须在模拟器上尝试。

我发现让 map 在模拟器上运行的最佳方法是使用另一个模拟器而不是 eclipse 模拟器。

搜索 Genymotion .是我试过的最好的模拟器。您可以使用 google play 下载任何应用程序,并且 map 可以正常工作。

对不起,我的英语不好。

关于android - 我们如何在模拟器上测试 Google Map API v2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17609300/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (https://www.ogeek.cn/) Powered by Discuz! X3.4