我制作的Android应用程序可以跟踪您的位置,最终在Google地图上绘制您的路线。一切似乎都在起作用,除了一件奇怪的事情,以前做过的事情。我想我没有改变任何对函数调用有用的东西,我发现的大多数例子都是这样做的。
在我的onCreate方法中,我执行以下操作:
LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
locationManager.requestLocationUpdates(
LocationManager.NETWORK_PROVIDER, 2000, 0, locationListener);
稍后我调用LocationListener:
LocationListener locationListener = new LocationListener() {
public void onLocationChanged(Location location) {
但不知怎的,这不会被调用。到处尝试记录,除了onLocationChanged
中的值之外,所有内容都返回了一个值。不能使用GPS_PROVIDER
所有相关代码:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tracking);
setUpMapIfNeeded();
// Acquire a reference to the system Location Manager
LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
// Tell the program to get location updates every 2 seconds(2000ms)
// I sadly don't get called..
locationManager.requestLocationUpdates(
LocationManager.NETWORK_PROVIDER, 2000, 0, locationListener);
}
LocationListener locationListener = new LocationListener() {
public void onLocationChanged(Location location) {
System.out.Println("I'm just here for debugging purposes");
System.out.Println("Sadly I don't appear in Logcat");
}
public void onStatusChanged(String provider, int status, Bundle extras) {
}
public void onProviderEnabled(String provider) {
}
public void onProviderDisabled(String provider) {
}
};
答案 0 :(得分:0)
您是否在清单文件中添加了权限?