适用于iOS版Google Maps SDK的可拆分标记 [英] Draggable marker with Google Maps SDK for iOS

查看:160
本文介绍了适用于iOS版Google Maps SDK的可拆分标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有人知道如何使用新的Google Maps SDK for iOS来实现可拖动标记? API本身并没有提供。功能请求已经提交。



如果我可以掌握GMSMarker的底层视图,我可以拦截Touch事件。任何人都试过这个?

解决方案

截至今天,您不需要使用外部类,只需将标记draggable

  GMSMarker * myMarker = [[GMSMarker alloc] ...] 
...
[myMarker setDraggable:YES];
//使用某种数据来识别每个标记,标记没有'标记',而'userData'是'id'类型
[myMarker setUserData:markerId];

并实现各自的代表

  @interface YourController:UIViewController&GMSMapViewDelegate> ... 

设置您的委托

  GMSMapView * myMapView = [[GMSMapView alloc] ...]; 
...
myMapView.delegate = self;

然后,您可以处理每个标记事件,即:


$ b $ (void)mapView:(GMSMapView *)mapView didEndDraggingMarker :( GMSMarker *)marker {
if([marker.userData isEqualtoString :@xMark])
NSLog(@标记拖到位置:%f,%f,marker.position.latitude,marker.position.longitude);
}


Has anybody figured out how to implement draggable markers with the new Google Maps SDK for iOS? The API does not provide it natively, yet. Feature request is already submitted.

If I could get a hold of the underlying view of the GMSMarker, I could intercept the Touch events. Anybody tried this?

解决方案

As of today, You don't need to use external classes, just make your markers "draggable"

GMSMarker *myMarker = [[GMSMarker alloc] ...];
...
[myMarker setDraggable: YES];
// Use some kind of data to identify each marker, marker does not have 'tag' but 'userData' that is an 'id' type
[myMarker setUserData: markerId];

And implement the respective delegate

@interface YourController: UIViewController<GMSMapViewDelegate> ...

Set your delegate

GMSMapView *myMapView = [[GMSMapView alloc] ...];
...
myMapView.delegate = self;

Then you can handle each marker event, ie:

-(void)mapView:(GMSMapView *)mapView didEndDraggingMarker:(GMSMarker *)marker{
    if ([marker.userData isEqualtoString:@"xMark"])
        NSLog(@"marker dragged to location: %f,%f", marker.position.latitude, marker.position.longitude);
}

这篇关于适用于iOS版Google Maps SDK的可拆分标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆