Map events
Map events
Implement any action you need to be triggered on one of the following map events:
-
Panning.
-
Single press.
-
Double press.
-
Long press.
To receive events you need to register id<TTMapViewDelegate> on map
Sample use case: In your app, users invoke one behavior with a single press and another with a long press.
Use the code snippets below in your app to catch map events. In this example, the action is simply to display a toast with latitude and longitude on each map event. Of course, you can implement other cool features instead.
- (void)mapView:(TTMapView *)mapView didPanning:(CLLocationCoordinate2D)coordinate {
- (void)mapView:(nonnull TTMapView *)mapView didDoubleTap:(CLLocationCoordinate2D)coordinate {
- (void)mapView:(nonnull TTMapView *)mapView didLongPress:(CLLocationCoordinate2D)coordinate {
In this example you will see a Toast with latitude and longitude of a point that was clicked on the map, but you can utilize these information in your own manner.
![]() Receive callbacks after the map panning |
![]() Receive callbacks after the map panning |
![]() Receive callbacks after the map panning |
Enable and disable gestures
You can disable gestures such as zooming, scrolling and rotating in your application by setting up an integer mask on properties like below:
Disable zooming gesture
self.mapView.disableGesturesMask = TTOptionGesturesDisableZoom;
Disable the rotating gesture
self.mapView.disableGesturesMask = TTOptionGesturesDisableRotate;
Disable the scrolling gesture
self.mapView.disableGesturesMask = TTOptionGesturesDisableScroll;
You can turn off more than one gesture by setting up the mask on properties like below:
// Disable scrolling and zooming gestures
self.mapView.disableGesturesMask = TTOptionGesturesDisableScroll | TTOptionGesturesDisableZoom;
If you want to enable gestures, setup the integer mask on a property like below:
self.mapView.disableGesturesMask = TTOptionGesturesDisableNone;