我已经用两个标记实现了谷歌地图,并在它们之间画了一条折线。现在我想以下面的方式显示标记图标。我尝试计算线的斜率。但是由于正负的倾斜,我无法修复它。 解决这个问题的任何方法或计算。
我想以这种方式实现两个标记图标(绘制一个(
我的代码
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));
}}
我认为差异需要是180度吗?
"第一个标记">
rotation(float angleInDegree)
和 "第二个标记">
rotation(float (angleInDegree + 180))