【问题标题】:Tap and hold to add pin google maps api ios [closed]点击并按住以添加 pin google maps api ios [关闭]
【发布时间】:2013-07-31 14:09:38
【问题描述】:

我想点击并按住map 以添加带有google maps api 的pin。 是IOS的教程吗?

GMSMarker *marker;

【问题讨论】:

标签: ios google-maps map


【解决方案1】:

您能否像使用 MKMapView 一样将 UILongPressGestureRecognizer 添加到您的 GMSMapView 中?我现在不在 Mac 上,所以我无法测试这个理论。

如果是,则使用 locationInView 检测屏幕上的触摸位置:

- (void)handleLongPressGesture:(UILongPressGestureRecognizer *)gesture
{ 
    CGPoint pointInView = [gesture locationInView:mapView];
}

然后找到相对于屏幕上点的位置坐标:

CLLocationCoordinate2D coordinate = [mapView.projection coordinateForPoint: point];

然后按照谷歌地图SDK文档Add a marker

GMSMarker *marker = [GMSMarker markerWithPosition:coordinate];
marker.title = @"Hello World";
marker.map = mapView;

希望对您有所帮助,或让您走上正轨。抱歉,我现在无法测试它是否有效!

【讨论】:

  • 成功了!谢谢你。我用它 'UILongPressGestureRecognizer *lpgr = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)]; lpgr.minimumPressDuration = 0.3; //用户需要长按2秒 [self.mapView addGestureRecognizer:lpgr];'
猜你喜欢
  • 2018-07-22
  • 1970-01-01
  • 2016-08-21
  • 1970-01-01
  • 2014-05-25
  • 2011-03-22
  • 2023-04-04
  • 2012-06-11
  • 2013-03-29
相关资源
最近更新 更多