1

Google Maps API for iOS を使用して、Google マップからカスタム オーバーレイ ビューを表示しようとしています。このオーバーレイ ビュー コンテンツ情報は、マーカーと 2 つのマイ ボタンです。しかし、これに関する参考文献が見つかりません。私の希望するオーバーレイビューは、以下のリンク付きの画像です。

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

これのガイドを教えてください!

4

5 に答える 5

5

おそらく、Google Maps Android API のドキュメントで公式に述べられているように、情報ウィンドウに関する以下の制限が Google Maps iOS SDK にも適用されます。

情報ウィンドウはライブ ビューではなく、ビューはマップ上に画像としてレンダリングされます。その結果、ビューに設定したリスナーは無視され、ビューのさまざまな部分のクリック イベントを区別できなくなります。ボタン、チェックボックス、テキスト入力などのインタラクティブなコンポーネントをカスタム情報ウィンドウ内に配置しないことをお勧めします。

基本的に、情報ウィンドウの任意の部分をクリックすると、「didTapWindowOfMarker」のみがトリガーされます

于 2013-03-07T20:34:36.713 に答える
2

これを実現する最善の方法は、GMSMapViewDelegate のメソッドを介して情報ウィンドウのカスタム ビューを GMSMapView に渡すことmapView:markerInfoWindow:です。

これを実現するには、GMSMapView インスタンスのデリゲートとして自分自身を次のように設定します。

self.mapView.delegate = self;

次に、要求されたときにカスタム 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;
}

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
 */
于 2013-02-25T18:48:12.103 に答える
2

わかりましたが、誰かがその UIView で UIButton を取得してタッチに応答する方法を明確にしてもらえますか? Dung Nguyen Le Hoang の添付写真の 2 つのボタンのように。たとえば、次のようなボタンを追加するとします。

- (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;
}

そしてもちろんbuttonPressedがあります

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

呼び出されません。ボタンをサブビューとして self.mapView に追加すると、InfoWindow ではなく mapView に表示され、もちろん、タッチに反応します。設定されていないフレームが原因だと思いますが、うまく取得できません。誰かが明確にしてもらえますか?

于 2013-02-26T08:04:38.877 に答える
0

ユーザーがmarkerInfoContentsをタップすると、2つのボタンでAlertViewまたはActionSheetを表示できます

于 2017-09-12T17:02:18.357 に答える