0
我是動畫汽車在街道上移動的實時位置更新。但是汽車正面向真北方,無論我正在朝哪個方向移動,軸承都會返回0.0。有沒有什麼破解讓我的車前方向我移動的方向移動。這是我的代碼。動畫汽車在地圖上的標記運動V2
private void draw_current_location(Location currentlocation) {
LatLng current = new LatLng(currentlocation.getLatitude(), currentlocation.getLongitude());
CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(current, 15);
map.animateCamera(cameraUpdate);
if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
return;
}
Location calculatedLoc = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if(locationManager.getProvider(LocationManager.GPS_PROVIDER).supportsBearing()) {
float bearing = calculatedLoc.bearingTo(currentlocation);
centeredMap(current, bearing);
}
}
void centeredMap(final LatLng lalng, float bearng){
Location l = new Location("");
l.setLatitude(lalng.latitude);
l.setLongitude(lalng.longitude);
View marker = ((LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.custom_marker_layout, null);
if (customMarker != null) customMarker.remove();
customMarker = map.addMarker(new MarkerOptions()
.position(lalng)
.title("Title")
.snippet("Description")
.anchor(0.5f, 0.5f)
.flat(true)
.rotation(bearng)
.icon(BitmapDescriptorFactory.fromResource(R.drawable.customIMAGE)));
Toast.makeText(getApplicationContext(), String.valueOf(l.getBearing()), Toast.LENGTH_SHORT).show();
customMarker.setPosition(lalng);
animation.animateMarker(l, customMarker);
}
更新:現在軸承正在返回值。在我編輯我的代碼之後。
if(locationManager.getProvider(LocationManager.GPS_PROVIDER).supportsBearing()) {
Location calculatedLoc = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
float bearing = calculatedLoc.bearingTo(currentlocation);
Toast.makeText(getApplicationContext(), String.valueOf(bearing), Toast.LENGTH_SHORT).show();
centeredMap(currentlocation, bearing);
}
但標記,因爲錨沿着中心垂直軸旋轉(.5f,.5f),但它不承認我的車標誌的前面,所以它不會沿街動畫。汽車只是朝北的靜態圖像,在我移動時被拖動。任何幫助將非常感激。