Es ist einfach, von Ihnen zu erreichen, setzen eine View
über die Karte und verwalten die 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;
}
});
}
}
Thanx viel .. es funktioniert super .. nur eine Sache wie analysiere ich was in der Sele cted Bereich wie zomato tut Ich möchte Schulen in ausgewählten Bereich von Benutzer finden – Aakash
Es gibt zu viele verschiedene gute Antworten auf diese Frage. Ich denke, du solltest eine andere Frage stellen, die deinen Hintergrund und deine Bedürfnisse erklärt, damit andere reiche Antworten geben können. – antonio