Make GMSCircle respond to tap?

坚强是说给别人听的谎言 提交于 2019-12-10 20:38:15

问题


I am using the Google Maps API for iOS and I want to make it so when you tap on a GMSCircle it pops up a little thing I coded elsewhere. I have set the circle to "tappable" but I cannot find what I need to set or make to listen for the tap. What do I use?

    CLLocationCoordinate2D circleCenter = CLLocationCoordinate2DMake(10,10);
GMSCircle *circ = [GMSCircle circleWithPosition:circleCenter
                                         radius:10];
circ.tappable = true;
[circ setFillColor:[UIColor colorWithRed:1 green:0 blue:0 alpha:.5]];

circ.map = mapView_;

回答1:


You need to use the delegate method didTapOverlay :

- (void) mapView: (GMSMapView *) mapView  didTapOverlay: (GMSOverlay *) overlay 

Here the parameter overlay indicates the overlay that was tapped. So you need to check if it equals circ.

EDIT : Adding details on how to check for circle within didTapOverlay

When GMSCircle is added to the map, a corresponding GMSPolygon is also created. If the circle is set as tappable, then on tapping it, the overlay passed to the didTapOverlay method is this related polygon and not the circle . So a direct comparison between the overlay and the circle is not possible. Hence as Raspu as pointed out, you can set a value in title using circ.title = and then inside didTapOverlay, you can check if overlay.title is same as circ.title. This works because the title property of the circle is within the corresponding polygon and hence will be present in the overlay parameter.



来源:https://stackoverflow.com/questions/17975273/make-gmscircle-respond-to-tap

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!