我是 android 开发的初学者。 问题是代码需要几分钟才能获取用户位置,所以我该如何解决这个问题? 请帮助我
LocationListener locationListener = new LocationListener() {
public void onLocationChanged(Location location) {
Toast.makeText(getBaseContext(),
"Location changed : Lat: " + location.getLatitude() +
" Lng: " + location .getLongitude(),
Toast.LENGTH_SHORT).show();
}
public void onStatusChanged(String provider, int status, Bundle extras) {}
public void onProviderEnabled(String provider) {}
public void onProviderDisabled(String provider) {}
};
lm.requestLocationUpdates(
LocationManager.GPS_PROVIDER,
0,
0,
locationListener);
最佳答案
GPS 启动总是很慢,而且在室内不起作用。您可能想阅读 this :
I'm a big fan of location-based apps, but not their seemingly-inevitable startup latency.
Whether it's finding a place to eat or searching for the nearest Boris Bike, I find the delay while waiting for the GPS to get a fix, and then for the results list to populate, to be interminable. Once I’m in a venue and ready to get some tips, check-in, or review the food, I’m frequently thwarted by a lack of data connection.
关于android - 获取用户位置的时间太长?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7213966/