【发布时间】:2020-10-17 15:54:00
【问题描述】:
我正在开展一个项目,该项目需要将用户的坐标精确到几米以内。我注意到,当我走在街上时,我手机上的 Google 地图应用会高度准确地跟踪我的运动,几乎总是在一米之内。
在我自己的项目中,我做了以下工作:
在我的 AndroidManifest.xml 中有:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
在我的 MainActivity.java 中,我有一个名为 recenter 的函数,如下所示:
private void recenter(Location location) {
LatLng user = new LatLng(location.getLatitude(), location.getLongitude());
userMarker.setPosition(user);
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(user, 20));
}
在我的onCreate 中,我使我们成为LocationManager 和LocationListener 就像这样(locationListener 被触发调用recenter):
locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
locationListener = new LocationListener() {
@Override
public void onLocationChanged(Location location) {
recenter(location);
}
...
};
在确保用户手动授予权限后,我运行以下命令:
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);
尽管如此,我的别针通常是几个,我会说大约 10 米。 是否可以在自制应用程序上获得谷歌地图级别的结果? 如果没有,谁能得到更准确的结果?
【问题讨论】:
标签: java android google-maps location