6

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

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

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

但以下标志表明位置设置不正确:

1.当我去maps.google.com或打开谷歌地图时,它总是抱怨无法确定我的位置,他们总是让我打开wifi

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

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

我去了以前指向这里的链接: 位置未在 android 模拟器中的新地理修复上更新

Android - 无法在模拟器上获取 gps 位置

模拟器上的 GPS 没有得到地理修复 - Android

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

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

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

4

2 回答 2

1

hope You will see icon and it will work.working on mine. APi Level 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;
    }

}

Manifest.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>

When icon is notified then you can just simply get the location by lm.getLastKnowLocationit will work

于 2013-02-09T12:41:20.927 回答
0

有时 AVD 本身存在问题。尝试切换到另一个 CPU 架构。我有类似的问题,通过在 ARM 和 Intel 之间切换来解决。有时启用 Google 服务的 AVD 也有帮助

还可以在开发人员选项中使用“允许模拟位置”

作为替代方案,你可以试试这个客户端: https ://github.com/RomanTheLegend/Pokemon_NoGo/tree/master/Sources/PokemonNoGo 我写它是为了玩口袋妖怪,但它适用于任何基于 GPS 的应用程序。它所做的只是接受来自桌面客户端的坐标并模拟主系统 GPS 提供程序 - LocationManager.GPS_PROVIDER

最后但同样重要的是:在 AVD 中,您可以重播 .kml 文件。有许多服务可以帮助您生成一个。或者只是安装“Lockito”并从 Android 生成假坐标

于 2016-08-23T10:36:43.297 回答