Car Animation Map Marker Movement V2

I enliven a car moving along the street with real-time location updates. But the car is facing true north, and the bearing returns 0.0 regardless of which direction Iโ€™m moving. Is there any hack for the front of my car to move the direction I'm moving. Here is my code.

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); } 

UPDATE: now the bearing returns values. After I edited my code as such.

 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); } 

But the marker rotates along the central vertical axis due to the anchor (.5f, .5f), but it DOES NOT RECOGNIZE my front car marker so that it does not animate along the street. A car is just a static image facing north, and it is pulled when I move. Any help would be greatly appreciated.

0
source share
1 answer

I have earned. I was going to pull my hair. I was even going to draw several cars with different rotation and animation between everyone with a switch or something else. But I didnโ€™t go that far. I had a static car, standing north with an anchor at (.5, .5) and drove a distance to the actual value, then it began to rotate and follow my direction. 1) The bearing is accurate only if the difference between the first and second values โ€‹โ€‹of the difference is several seconds. (The closer the location, the lower the accuracy of the bearing). To do this, itโ€™s best to grab places farther apart and change direction based on the bearing you are getting; which is not real-time animation (with some delay, but great animation that looks like real). 2) You must use a GPS provider to receive the bearing.

0
source

All Articles