[英]Android GPS app not working on Emulator
I have unsuccessfully attempted to get GPS Location to work for my app under Android. 我没有成功尝试让GPS位置适用于Android下的应用程序。 I would like to know what I might be doing wrong.
我想知道我可能做错了什么。 I have so far tried the following methods:
到目前为止,我尝试了以下方法:
as well as many others, but all in vain. 以及其他许多人,但都是徒劳的。
Considering that all the solutions above worked for some or the other person, I will use this one to debug: 考虑到上面的所有解决方案都适用于某些人,我将使用此解决方案进行调试:
package my.namespace;
import android.app.Activity;
import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;
public class HomeActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
LocationListener ll = new mylocationlistener();
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, ll);
}
private class mylocationlistener implements LocationListener {
public void onLocationChanged(Location location) {
if (location != null) {
Log.d("LOCATION CHANGED", location.getLatitude() + "");
Log.d("LOCATION CHANGED", location.getLongitude() + "");
Toast.makeText(HomeActivity.this,
location.getLatitude() + "" + location.getLongitude(),
Toast.LENGTH_LONG).show();
}
}
public void onProviderDisabled(String provider) {
}
public void onProviderEnabled(String provider) {
}
public void onStatusChanged(String provider, int status, Bundle extras) {
}
}
}
There were @override
annotations for the 3 methods onProviderDisabled
, onProviderEnabled
and onStatusChanged
. 在
onProviderDisabled
, onProviderEnabled
和onStatusChanged
有3个方法的@override
注释。 I had to remove them because Eclipse gave an error that these methods are not overriding a superclass. 我不得不删除它们,因为Eclipse给出了一个错误,即这些方法不会覆盖超类。
I have added the permissions in the manifest file ( ACCESS_FINE_LOCATION
, ACCESS_MOCK_LOCATION
, ACCESS_COARSE_LOCATION
and INTERNET
). 我已在清单文件中添加了权限(
ACCESS_FINE_LOCATION
, ACCESS_MOCK_LOCATION
, ACCESS_COARSE_LOCATION
和INTERNET
)。
Does anyone have an idea what I might be doing wrong? 有谁知道我可能做错了什么?
Edit: running on Emulator (Android 2.2 API 8) 编辑:在模拟器上运行(Android 2.2 API 8)
Make sure to enable GPS when you test your app. 确保在测试应用时启用GPS。 It would also help if you use NETWORK_PROVIDER and GPS_PROVIDER both.
如果您同时使用NETWORK_PROVIDER和GPS_PROVIDER,它也会有所帮助。 So that when GPS is not available you still get the location with NETWORK_PROVIDER.
因此,当GPS不可用时,您仍然可以使用NETWORK_PROVIDER获取该位置。
UPDATE: Also, if you are using emulator to test your app, make sure you emulate the GPS fix either from command line or using Eclipse. 更新:此外,如果您使用模拟器测试您的应用程序,请确保您从命令行或使用Eclipse模拟GPS修复。 here is a link to stackoverflow question about how to do this How to emulate GPS location in the Android Emulator?
这里有一个关于如何执行此操作的stackoverflow问题的链接如何在Android模拟器中模拟GPS位置?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.