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

kks*_*eed 6 gps android emulation

我目前正在Android中测试gps位置(使用SDK Tools rev 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).似乎什么也没发生.

我之前的链接指向这里: 位置没有更新Android模拟器中的新geo修复

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

模拟器上的GPS无法获得地理定位 - Android

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

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

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

Usm*_*iaz 1

希望你会看到图标并且它会起作用。正在我的上工作。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;
    }

}
Run Code Online (Sandbox Code Playgroud)

清单.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>
Run Code Online (Sandbox Code Playgroud)

当图标被通知时,您只需简单地获取位置就可以lm.getLastKnowLocation