android 模拟器 geo fix 无法设置 gps 位置

标签 android gps emulation

我目前正在 Android 中测试 gps 位置(使用 SDK 工具版本 21.0.1。我尝试了标准程序:

  1. 创建一个启用 GPS 的模拟器(尝试了多个版本,从 2.1 到 4.2)
  2. 启动模拟器
  3. telnet 到 localhost:5554
  4. 输入 geo fix long lat

理论上,这应该将 gps 设置为 .

但有以下迹象表明位置设置不正确:

<强>1。当我去 maps.google.com 或打开谷歌地图时,它总是提示无法确定我的位置,他们总是要求我打开 wifi。

<强>2。 GPS 似乎从未被激活——状态栏上没有图标。

此外,我尝试了 DDMS(已弃用,当然我也尝试了 Monitor)。似乎什么都没发生。

我去了之前指向这里的链接: Location not being updated on new geo fix in android emulator

Android - Unable to get the gps location on the emulator

GPS on emulator doesn't get the geo fix - Android

但所有这些链接似乎都无济于事。 android 项目页面上有一些错误报告: http://code.google.com/p/android/issues/detail?id=13046

但这是一个相当老的问题,尚未达成最终解决方案。

我想知道是否有其他人遇到过类似问题,请提供一些帮助。谢谢。

最佳答案

希望您会看到图标并且它会起作用。在我的上工作。 API 级别 10

package com.example.locationsddf;

import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.TextView;

public class MainActivity extends Activity {

    LocationManager lm;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        final TextView tv = (TextView) findViewById(R.id.tv);
        lm = (LocationManager) getSystemService(LOCATION_SERVICE);
        lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, new LocationListener() {

            @Override
            public void onStatusChanged(String arg0, int arg1, Bundle arg2) {
                // TODO Auto-generated method stub

            }

            @Override
            public void onProviderEnabled(String arg0) {
                // TODO Auto-generated method stub

            }

            @Override
            public void onProviderDisabled(String arg0) {
                // TODO Auto-generated method stub

            }

            @Override
            public void onLocationChanged(Location arg0) {
                tv.setText("Latitude: "+arg0.getLatitude()+" \nLongitude: "+arg0.getLongitude());

            }
        });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }

}

list .xml

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

    <uses-sdk
        android:minSdkVersion="5"
        android:targetSdkVersion="10" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION"/>

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

</manifest>

当通知图标时,您只需通过 lm.getLastKnowLocation 获取位置即可

关于android 模拟器 geo fix 无法设置 gps 位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14784398/

相关文章:

C++:对象属性模拟:思想

android - 在 Android 模拟器(Mac 控制台)中播放 .apk 文件

java - android中的layoutinflater nullpointerexception

Android - 如何确定是否连接了外部扬声器

javascript - 为什么这个圆公式在 Javascript 中给出的是椭圆体,而在 Python 中给出的是圆?

iOS:是否可以要求核心位置框架仅使用蜂窝塔或仅使用 WiFi 或使用 GPS 天线来获取位置?

android - 如何防止 Google Map V2 Android 中的蓝点更新?

java - 使用密码输入时的Edittext字段不隐藏密码

iphone - GPS 坐标(以度为单位)来计算距离

eclipse - 关于在 Eclipse 中启动 webOS 模拟器的一些新手问题