2013-02-09 177 views
6

目前我测试的GPS位置在Android中(与SDK工具修订版21.0.1我尝试了标准程序:Android模拟器地理修复无法设置GPS定位

  1. 创建一个模拟器启用GPS(试过多种版本,从2.1到4.2)
  2. 启动模拟器
  3. 的telnet到localhost:5554个
  4. 类型地理修复长纬度

理论上,这应该设置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

但这是一个很老的问题,并没有达到最终的解决方案。

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

+0

我绝对可以证实这一点。它不起作用。有趣的是,如果我使用Android 2.1(或其他非常古老的东西)设置AVD,它的功能就像是一种魅力:geo修复了较长的纬度,并且该位置立即显示在Google地图应用中... – decades 2013-02-21 20:55:27

回答

1

希望你会看到图标,它会work.working在我的。 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

<?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的位置,将工作

+0

我只是遵循你的代码,我可以证实onLocationChanged事件被解雇并且收到了位置。但是,为什么像谷歌地图这样的应用程序,他们不是对GPS位置变化作出响应,仍然显示“无法确定你的位置”等信息? – kkspeed 2013-02-10 09:23:38

+0

如果这就是答案,你可以通过点击我帖子的左上角标记我的帖子为答案。你可以发布你的Logcat信息吗? – 2013-02-10 14:13:54

0

有时也有与AVD本身的问题。尝试切换到另一个CPU架构。我遇到过类似的问题,并通过在ARM和英特尔之间切换来解决。有时与谷歌服务AVD启用也帮助

还玩弄“允许模拟位置”,在开发者选项

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

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

相关问题