gpt4 book ai didi

ios - 将长按手势识别器添加到 iOS 中的 Google map

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:58:18 24 4
gpt4 key购买 nike

我向 UIScrollView 添加了一个 GMSMapView,并且还向该 UIScrollView 添加了 TableView 。不,我的任务是,如果长按 map 上的任何位置,我将获取该地址并将该地址添加到表格 View 中,而且我想在该位置添加一个标记。

我编写了下面的代码来向 map 添加长按手势识别器,但它不起作用。

- (void)viewDidLoad
{
[super viewDidLoad];
self->map.delegate = self;
CGRect fullScreenRect=[[UIScreen mainScreen] applicationFrame];
UIScrollView *scroll=[[UIScrollView alloc] initWithFrame:fullScreenRect];
[self.view addSubview:scroll];
scroll.contentSize=CGSizeMake(320,1000);
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:21.0000 longitude:78.0000 zoom:4.5];
map = [GMSMapView mapWithFrame:CGRectMake(0,0, self.view.frame.size.width,390) camera:camera];
[scroll addSubview:map];

UITableView *tab = [[UITableView alloc]initWithFrame:CGRectMake(0, 410, self.view.bounds.size.width, 300) style:UITableViewStylePlain];
[scroll addSubview:tab];

tab.delegate = self;
tab.dataSource = self;

UILongPressGestureRecognizer *longPressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(mapLongPress:)];
longPressGesture.minimumPressDuration = 1.5;
[map addGestureRecognizer:longPressGesture];
}

-(void)mapLongPress:(UILongPressGestureRecognizer *)gestureRecognizer
{
if(gestureRecognizer.state == UIGestureRecognizerStateBegan)
{
NSLog(@"%f",coordinate.latitude);
NSLog(@"%f",coordinate.longitude);
}
}

这里的主要问题是“mapLongPress”方法在我长按 MapView 后没有被调用。
谁能帮帮我。

最佳答案

您可以使用默认的 MapVIew LongPress 事件

  /**
* Called after a long-press gesture at a particular coordinate.
*
* @param mapView The map view that was pressed.
* @param coordinate The location that was pressed.
*/
- (void)mapView:(GMSMapView *)mapView
didLongPressAtCoordinate:(CLLocationCoordinate2D)coordinate;

关于ios - 将长按手势识别器添加到 iOS 中的 Google map ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22704407/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com