我已经使用两个标记实现了谷歌地图,并在它们之间绘制折线。现在我想以下面的方式显示标记图标。我试着计算线的斜率。但由于积极和消极的倾斜,我无法解决它。 任何方法或计算来解决这个问题。
I would like to implement the two marker icon in that way ( the draw one)
我的代码
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {
private GoogleMap mMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(map);
mapFragment.getMapAsync(this);
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
BitmapDescriptor icon = BitmapDescriptorFactory.
fromResource(R.mipmap.map_icon);
double x1,x2,y1,y2;
x1 = 70.2048;
y1 = 60.2529;
x2 = 80.0902;
y2 = 138.7129;
LatLng dhaka = new LatLng(x1, y1);
LatLng chittagong = new LatLng(x2, y2);
double slopeOfThePolyLine = (y2-y1)/(x2-x1);
double angle = Math.atan(slopeOfThePolyLine);
double angleInDegree = angle * 57.2958;
mMap.addMarker(new MarkerOptions().position(dhaka).title("First Marker").
anchor(.5f, .5f).
// rotation((float) angle1).
flat(true).icon(icon));
mMap.addMarker(new MarkerOptions().position(chittagong).
title("Second Marker").
// rotation((float) (90 + angleInDegree)).
anchor(.5f, .5f).flat(true).icon(icon));
Polyline line = mMap.addPolyline(new PolylineOptions()
.add(dhaka, chittagong)
.width(5)
.color(Color.RED));
mMap.moveCamera(CameraUpdateFactory.newLatLng(dhaka));
}}
答案 0 :(得分:0)
我认为差异需要180度?
" First Marker"
rotation(float angleInDegree)
和 "第二个标记"
rotation(float (angleInDegree + 180))