您好我正在尝试制作跟踪类型的移动应用程序。我需要要求GPS点经纬度更准确。
如您所知,我们可以使用Android中的两种方法获取位置点。
第一种方法:使用Location API获取实时位置点。这是要执行的虚拟代码
// Acquire a reference to the system Location Manager
LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
// Define a listener that responds to location updates
LocationListener locationListener = new LocationListener() {
public void onLocationChanged(Location location) {
// Called when a new location is found by the network location provider.
makeUseOfNewLocation(location);
}
public void onStatusChanged(String provider, int status, Bundle extras) {}
public void onProviderEnabled(String provider) {}
public void onProviderDisabled(String provider) {}
};
// Register the listener with the Location Manager to receive location updates
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);
我设置了GPS_PROVIDER
以获得更准确的位置并将minTime
值设置为0并且位置更新值之间的最小距离值为0
第二种方法:使用使用融合位置提供程序检索位置点的Google Play服务APK来获取位置
public class MainActivity extends FragmentActivity implements
GooglePlayServicesClient.ConnectionCallbacks,
GooglePlayServicesClient.OnConnectionFailedListener,
LocationListener {
// Define an object that holds accuracy and frequency parameters
LocationRequest mLocationRequest;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Create the LocationRequest object
mLocationRequest = LocationRequest.create();
// Use high accuracy
mLocationRequest.setPriority(
LocationRequest.PRIORITY_HIGH_ACCURACY);
// Set the update interval to 5 seconds
mLocationRequest.setInterval(UPDATE_INTERVAL);
// Set the fastest update interval to 0 second
mLocationRequest.setFastestInterval(FASTEST_INTERVAL);
...
}
...
// Define the callback method that receives location updates
@Override
public void onLocationChanged(Location location) {
// Report to the UI that the location was updated
String msg = "Updated Location: " +
Double.toString(location.getLatitude()) + "," +
Double.toString(location.getLongitude());
Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
}
...
}
所以两者都做同样的事情来检索Android中的位置。我尝试使用相同的Google Play服务概念来制作Geo Fence,但这对我来说并不合适。
无论如何,我怀疑现在哪种方法被认为是检索更准确位置的最佳方法,并且应该适用于所有环境。
提前致谢。
答案 0 :(得分:0)
有疑问哪种方法被视为最佳
这非常接近基于意见的答案,但我认为融合的提供商是更好的方式,因为它改进了LocationManager
的技术。它不仅管理哪个提供商最适合当前的手机状态,还增加了传感器以提供更准确的结果。您无法获得比GPS更准确的信息,但如果无法使用GPS,融合的提供商将尝试获得最佳位置。
应该适用于所有环境。
您无法保证其中任何一个都适用于所有环境。这样说,谷歌发布融合提供商的主要原因之一是解决GPS无处不在的事实(即建筑物内部)。因此,他们使用侧面传感器上的其他提供商(WiFi,网络等)来提供最佳位置。