eclipse 模拟器上的 GPS 没有得到地理定位 - Android

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/896889/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 13:44:03  来源:igfitidea点击:

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

androideclipsegps

提问by Maurizio Pozzobon

I'm developing an application for the android OS, I'm just starting, but I can't get the GPS on the emulator to work. I've read on the internet that you need to send a geo fix to the emulator in order to enable the gps locationProvider. I'm both using the DDMS and telnet to try to send it, but logcat never tells me the it recived a new fix, and my apolication still sees the gps as disabled

我正在为 android 操作系统开发应用程序,我刚刚开始,但我无法让模拟器上的 GPS 工作。我在互联网上读到您需要向模拟器发送地理定位才能启用 gps locationProvider。我同时使用 DDMS 和 telnet 尝试发送它,但 logcat 从未告诉我它收到了新的修复程序,我的道歉仍然认为 gps 已禁用

here's my code

这是我的代码

package eu.mauriziopz.gps;

import java.util.Iterator;
import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.location.LocationManager;
import android.os.Bundle;
import android.util.Log;

public class ggps extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        LocationManager l =(LocationManager) getSystemService(Context.LOCATION_SERVICE);
        List<String> li = l.getAllProviders();
        for (Iterator<String> iterator = li.iterator(); iterator.hasNext();) {
            String string =  iterator.next();
            Log.d("gps", string);
        }
        if (l.getLastKnownLocation("gps")==null)
            Log.d("gps", "null");   
    }
}

I've read that the DDMS may not work properly on a non english OS, but telnet should work!

我读到 DDMS 在非英语操作系统上可能无法正常工作,但 telnet 应该可以工作!

update: the gps is enabled in the settings

更新:在设置中启用了 GPS

采纳答案by Maurizio Pozzobon

Turns out, that since I was developing for Android 1.5 (and not Google API 1.5) the map (and looks like other features) were disabled. As soon as I changed the target platform, my error disappeared.

事实证明,因为我是为 Android 1.5(而不是 Google API 1.5)开发的,所以地图(看起来像其他功能)被禁用了。一旦我改变了目标平台,我的错误就消失了。

btw thanks all

btw 谢谢大家

回答by Tughi

To test if the geofix is working you could use the Google Maps app with "My Location"

要测试地理定位是否正常工作,您可以使用带有“我的位置”的 Google 地图应用程序

回答by Jiju Induchoodan

Make sure that the gps in enabled in the settings. If still the problem persists, you just go to the application named Navigation in the main menu, run it and exit. Now try your application. You can enable location controls under emulator control in DDMS perspective by selecting a particular device. without selecting a device it will not work

确保在设置中启用了 GPS。如果问题仍然存在,您只需转到主菜单中名为 Navigation 的应用程序,运行它并退出。现在试试你的应用程序。您可以通过选择特定设备在 DDMS 透视图中启用模拟器控制下的位置控制。不选择设备就行不通

回答by CHiRo79

I supose is fixed yet, but in the code you should use as provider a string returned by the LocationManager service, instead of "gps" as you put in l.getLastKnownLocation("gps").

我认为是固定的,但在代码中,你应该使用 LocationManager 服务返回的字符串作为提供者,而不是你输入的“gps” l.getLastKnownLocation("gps")