演示在这里: - https://www.youtube.com/watch?v=a-xV6rFYT_0
我想做同样的事但是怎么办呢? 它是否覆盖......是的,那么他们如何跟踪圈内?
答案 0 :(得分:0)
您可以轻松地将View
放在地图上并管理MotionEvent
s:
<强> activity_maps.xml 强>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.SupportMapFragment" />
<View
android:id="@+id/draggable"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true" />
</RelativeLayout>
<强> MapsActivity.java 强>
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {
private GoogleMap mMap;
private View draggableView;
private List<LatLng> polylinePoints = new ArrayList<>();
private Polyline polyline;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
((SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map)).getMapAsync(this);
draggableView = findViewById(R.id.draggable);
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
draggableView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
LatLng position = mMap.getProjection().fromScreenLocation(
new Point((int) motionEvent.getX(), (int) motionEvent.getY()));
if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
if (polyline != null) {
polyline.remove();
polyline = null;
polylinePoints.clear();
}
polylinePoints.add(position);
polyline = mMap.addPolyline(new PolylineOptions().addAll(polylinePoints));
} else if (motionEvent.getAction() == MotionEvent.ACTION_MOVE){
polylinePoints.add(position);
polyline.setPoints(polylinePoints);
} else if (motionEvent.getAction() == MotionEvent.ACTION_UP) {
// Close the polyline?
// Send the polyline to make a search?
}
return true;
}
});
}
}