简体   繁体   English

当我在iOS中点击google上的标记时,如何使用两个按钮显示叠加信息视图

[英]How to show overlay info view with two button more when i click a marker on google in iOS

I am trying to show a custom overlay view from the Google Maps through the Google Maps API for iOS. 我正在尝试通过iOS版Google Maps API从Google Maps中显示自定义叠加视图。 This overlay view content info of marker, and two my button. 此叠加层查看标记的内容信息,以及两个我的按钮。 But I cannot find any references for this. 但是我找不到任何参考。 My desired overlay view is as image with link below: 我想要的叠加视图是带有以下链接的图像:

http://i1121.photobucket.com/albums/l515/dungnlh_khtn07/NguoiMoCay/overlayinfoview_zps8110b7ed.jpg http://i1121.photobucket.com/albums/l515/dungnlh_khtn07/NguoiMoCay/overlayinfoview_zps8110b7ed.jpg

Please give me a guide for this! 请给我一个指导!

Possibly, as mentioned officially in documentation of Google Maps Android API, the below restriction regarding infowindows applies to Google Maps iOs SDK also : 可能,正如Google Maps Android API文档中正式提到的那样,以下有关信息窗口的限制也适用于Google Maps iOs SDK:

Info window is not a live View, rather the view is rendered as an image onto the map. 信息窗口不是实时视图,而是将视图作为图像渲染到地图上。 As a result, any listeners you set on the view are disregarded and you cannot distinguish between click events on various parts of the view. 结果,您在视图上设置的所有侦听器都将被忽略,并且您无法区分视图各个部分上的单击事件。 You are advised not to place interactive components — such as buttons, checkboxes, or text inputs — within your custom info window. 建议您不要在自定义信息窗口中放置交互式组件,例如按钮,复选框或文本输入。

So bascially clicking on any part of the infowindow will trigger only "didTapWindowOfMarker" 因此,基本上单击信息窗口的任何部分将仅触发“ didTapWindowOfMarker”

The best way of achieving this is to pass your GMSMapView a custom view for your info windows via the GMSMapViewDelegate's mapView:markerInfoWindow: method. 实现此目的的最好方法是通过GMSMapViewDelegate的mapView:markerInfoWindow:方法为您的信息窗口传递GMSMapView的自定义视图。

To accomplish this, set yourself up as the delegate for your GMSMapView instance, like so: 为此,请将您自己设置为GMSMapView实例的委托,如下所示:

self.mapView.delegate = self;

Then return a custom UIView when requested: 然后在请求时返回自定义UIView:

- (UIView *)mapView:(GMSMapView *)mapView markerInfoWindow:(id<GMSMarker>)marker
{
    UIView *customView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
    customView.backgroundColor = [UIColor redColor];

    return customView;
}

You can find a little more information by looking in the GMSMapView header, which states: 您可以通过查看GMSMapView标头找到更多信息,该标头指出:

/**
 * Called when a marker is about to become selected, and provides an optional
 * custom info window to use for that marker if this method returns a UIView.
 * If you change this view after this method is called, those changes will not
 * necessarily be reflected in the rendered version.
 *
 * The returned UIView must not have bounds greater than 500 points on either
 * dimension.  As there is only one info window shown at any time, the returned
 * view may be reused between other info windows.
 *
 * @return The custom info window for the specified marker, or nil for default
 */

OK, but can someone please clarify how to get a UIButton on that UIView to respond to touches? 好的,但是有人可以澄清一下如何在该UIView上获取UIButton来响应触摸吗? Like two buttons in Dung Nguyen Le Hoang's attached picture. 就像粪阮勒昂(Dung Nguyen Le Hoang)所附图片中的两个按钮一样。 For example, if I add a button like this: 例如,如果我添加这样的按钮:

- (UIView *)mapView:(GMSMapView *)mapView markerInfoWindow:(id<GMSMarker>)marker
{
    UIView *customView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
    customView.backgroundColor = [UIColor redColor];

    UIButton *button = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    [button addTarget:self action:@selector(buttonPressed) forControlEvents:UIControlEventTouchUpInside];
    [button setFrame:CGRectMake(0, 0, 30, 30)];

    [customView addSubview:button];

    return customView;
}

and of course have buttonPressed 当然还有buttonPressed

- (void)buttonPressed
{
    NSLog(@"Hello");
}

it doesn't get called. 它不会被调用。 If I added the button as a subview to self.mapView then it appears on mapView, not InfoWindow and, of course, is responsive to touches. 如果我将按钮添加为self.mapView的子视图,则它会出现在mapView而不是InfoWindow上,并且当然会响应触摸。 I suppose it's due to some unset frames, but can't quite get it. 我想这是由于某些未设置的帧而导致的,但不能完全理解。 Can someone please clarify? 有人可以澄清一下吗?

  • (void)mapView:(GMSMapView *)mapView didTapInfoWindowOfMarker:(GMSMarker *)marker

您可以显示AlertViewActionSheet有两个按钮时,在markerInfoContents用户水龙头

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在不点击标记的情况下在 iOS 谷歌地图中显示信息窗口? - How to show a Info window in iOS Google maps without tapping on Marker? 当我单击IOS中的按钮时,为什么视图不显示? - Why the view doesn't show when I click the button in IOS? 如何在ios上添加一个按钮到谷歌地图标记信息窗口? - How can i add a button to google maps marker info window on ios? 当我点击地图时如何在 IOS 中一起显示标记和信息窗口 - How to show marker and info window together in IOS when i tap on map 如何以编程方式点击ios谷歌地图标记或显示标记的信息窗口? - How to tap on ios google map marker programatically or show info window of marker? 如何在 iOS 中的图表上默认将自定义视图显示为标记 - How can I show custom view as marker by default on Charts in iOS Xamarin.iOS上的自定义Google Maps标记信息视图 - Custom Google Maps marker info view on Xamarin.iOS 如何在iOS谷歌地图中显示所有信息窗口而无需点击标记? - How to show all Info window in iOS Google maps without tapping on Marker? 当我单击更多按钮而不是我离开的VC时,如何返回iOS中MOre…按钮的“表格” - How can I go back to the “Table” of a MOre… button in iOS when I click the more button and not the VC I left from Google Maps iOS-点击标记以显示默认的Google路线按钮 - Google Maps iOS - Tapping on Marker to show default google directions button
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM