简体   繁体   English

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

[英]android emulator geo fix is unable to set gps location

I'm currently testing gps locations in Android(with SDK Tools rev 21.0.1. I tried the standard procedure: 我目前正在Android中测试gps位置(使用SDK Tools rev 21.0.1。我尝试了标准程序:

  1. Create an emulator with GPS enabled(tried multiple version, from 2.1 to 4.2) 创建启用了GPS的模拟器(尝试多个版本,从2.1到4.2)
  2. Start the emulator 启动模拟器
  3. telnet to localhost:5554 telnet到localhost:5554
  4. Type geo fix long lat 键入geo fix long lat

In theory, this should set the gps to . 从理论上讲,这应该将gps设置为。

But the following signs indicate the location is not properly set: 但以下迹象表明位置未正确设置:

1. When I go to maps.google.com or open Google map, it always complains that cannot decide my location and they always ask me to switch on wifi . 1.当我去maps.google.com或打开谷歌地图时,它总是抱怨无法确定我的位置,他们总是要求我打开wifi

2. The GPS never seems to be activated -- no icons on the status bar. 2.似乎永远不会激活GPS - 状态栏上没有图标。

Also, I tried DDMS(which is deprecated and of course I tried Monitor as well). 此外,我尝试了DDMS(已弃用,当然我也尝试过Monitor)。 Nothing seems to happen. 似乎什么也没发生。

I went previous links pointed here: Location not being updated on new geo fix in android emulator 我之前的链接指向这里: 位置没有更新Android模拟器中的新geo修复

Android - Unable to get the gps location on the emulator Android - 无法在模拟器上获取gps位置

GPS on emulator doesn't get the geo fix - Android 模拟器上的GPS无法获得地理定位 - Android

But all those links do not seem to help. 但所有这些链接似乎没有帮助。 There are some bug report on android project page: http://code.google.com/p/android/issues/detail?id=13046 android项目页面上有一些错误报告: http//code.google.com/p/android/issues/detail?id = 13046

but it was a pretty old issue and a final solution wasn't reached. 但这是一个相当古老的问题,并未达成最终解决方案。

I'm wondering if anyone else has experienced similar issue and please offer some help. 我想知道是否有其他人遇到类似的问题,请提供一些帮助。 Thanks. 谢谢。

hope You will see icon and it will work.working on mine. 希望你会看到图标,它会工作。我的工作。 APi Level 10 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;
    }

}

Manifest.xml 的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.getLastKnowLocation it will work 当图标被通知时,您只需通过lm.getLastKnowLocation获取位置lm.getLastKnowLocation

Sometimes there are issues with AVD itself. 有时AVD本身存在问题。 Try switching to another CPU architecture. 尝试切换到另一种CPU架构。 I had similar issues and that was resolved by switching between ARM and Intel. 我有类似的问题,通过在ARM和英特尔之间切换解决了这个问题。 Sometimes AVD with Google services enabled also helped 有时启用Google服务的AVD也有帮助

Also play around with "Allow Mock Locations" in Developers options 还可以在开发人员选项中使用“允许模拟位置”

As an alternative, you could try this client: https://github.com/RomanTheLegend/Pokemon_NoGo/tree/master/Sources/PokemonNoGo I wrote it to play Pokemons, but it works with any GPS-based app. 作为替代方案,您可以尝试这个客户端: https//github.com/RomanTheLegend/Pokemon_NoGo/tree/master/Sources/PokemonNoGo我写它来玩Pokemons,但它适用于任何基于GPS的应用程序。 All it does is accept coordinates from desktop client and mocks main system GPS provider - LocationManager.GPS_PROVIDER 它所做的就是接受来自桌面客户端和模拟主系统GPS提供商的坐标 - LocationManager.GPS_PROVIDER

Last but not least: in AVD you can replay .kml files. 最后但并非最不重要:在AVD中,您可以重放.kml文件。 There are many services which could help you generate one. 有许多服务可以帮助您生成一个。 Or just install "Lockito" and generate fake coordinates from Android 或者只需安装“Lockito”并从Android生成虚假坐标

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM