本文介绍了我想将图标从一个位置点移动到另一个位置,图标应该在android中将一个位置移动到另一个位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在开发一款汽车应用程序。我想将图标移动到 android
中的另一个位置。我已尝试删除旧地图图标并清除所有图标并生成新图标。它工作完美。但它看起来不太好。我想将图标从一个位置移动到像 Ola app
这样的新位置,并且我正在使用汽车图标,因此我想在将位置更改为90度时转弯图标。
I am working on a car tacking app. I want to move the icon to another location in android
I had already tried to remove old map icon and clearing all icons and generating new icon. It is working perfectly. But it's not looking good. I want to move the icon from one location to a new location like Ola app
and I am using car icon so I want turn icon when change the location into 90 degrees.
推荐答案
private double bearingBetweenLocations(LatLng latLng1, LatLng latLng2) {
final double PI = 3.14159;
final double lat1 = latLng1.latitude * PI / 180;
final double long1 = latLng1.longitude * PI / 180;
final double lat2 = latLng2.latitude * PI / 180;
final double long2 = latLng2.longitude * PI / 180;
final double dLon = (long2 - long1);
final double y = Math.sin(dLon) * Math.cos(lat2);
final double x = Math.cos(lat1) * Math.sin(lat2) - Math.sin(lat1)
* Math.cos(lat2) * Math.cos(dLon);
double brng = Math.atan2(y, x);
brng = Math.toDegrees(brng);
brng = (brng + 360) % 360;
return brng;
}
计算旋转角度。然后 onLocationChanged()
再次设置图片:
Calculate the degree of rotation.And then onLocationChanged()
set the image again:
@Override
public void onLocationChanged(Location location) {
if (location == null)
return;
if (mMap != null) {
if (mPositionMarker != null && mPositionMarker.isVisible()) {
mPositionMarker.remove();
}
newLatLng = new LatLng(location.getLatitude(), location.getLongitude());
if (oldLatLng != null) {
mPositionMarker = mMap.addMarker(new MarkerOptions()
.flat(true)
.anchor(0.5f, 0.5f).icon(BitmapDescriptorFactory
.fromResource(R.drawable.ic_cab_top)).rotation((float) bearingBetweenLocations(newLatLng, oldLatLng))
.position(new LatLng(location.getLatitude(), location
.getLongitude())));
animateMarker(mPositionMarker, location); // Helper method for smooth animation
mMap.animateCamera(CameraUpdateFactory.newLatLng(new LatLng(location
.getLatitude(), location.getLongitude())));
}
oldLatLng = newLatLng;
}
这篇关于我想将图标从一个位置点移动到另一个位置,图标应该在android中将一个位置移动到另一个位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!