Ajout d'un événement Click sur InfoWindow / Marker dans Google Maps SDK pour iOS natif / objective C

Question simple

Je travaille sur une application pour iOS où j'ai embedded la nouvelle carte Google pour iOS natif. Tout fonctionne bien sauf un problème où je ne peux pas find une solution de propper pour IOS / Objective-C natif ni ici ni à google (s'il y en a un s'il vous plaît me montrer et désolé de vous ennuyer)

Ce que je veux: Je veux que l'user clique sur le marqueur qui ouvre la window d'information. Après avoir cliqué ou tapé sur la window d'information, il devrait ouvrir un nouvel UIView avec d'autres informations.

Comment puis je faire ça?

Merci pour les conseils

1.conforme au protocole GMSMapViewDelegate .

 @interface YourViewController () <GMSMapViewDelegate> // your properties @end 

2. Mettez votre délégué mapView_ .

 mapView_.delegate = self; 

3.implement de la méthode GMSMapViewDelegate

 - (void)mapView:(GMSMapView *)mapView didTapInfoWindowOfMarker:(GMSMarker *)marker { // your code } 

btw, marker.userData est utile. vous pouvez y placer vos données nécessaires et les utiliser dans - mapView:didTapInfoWindowOfMarker:

où vous ajoutez Map, ajoutez

  mapView_.delegate=self; 

alors utilisez ceci

 -(void)mapView:(GMSMapView *)mapView didTapInfoWindowOfMarker:(id<GMSMarker>)marker{ //info window tapped } 

J'utilise Google Maps SDK pour iOS.

J'ai sous-classé uiview pour créer une vue personnalisée "InfoWindow" pour infowindow.

add @property (nonatomic, retain) UIView * actionOverlayCalloutView; dans le file d'en-tête de votre viewcontroller.

 - (UIView *)mapView:(GMSMapView *)mapView markerInfoWindow:(GMSMarker *)marker { if(self.objSelectedParking != nil) { float anchorSize = 0.5f; float infoWindowWidth = 250.0f; float infoWindowHeight = 250.0f; [self.actionOverlayCalloutView removeFromSuperview]; InfoWindow *infoWindow = [[InfoWindow alloc] initWithFrame:CGRectMake(0, 0, infoWindowWidth, infoWindowHeight)]; infoWindow.lblTitle.text = self.objSelectedParking.strParkingName; infoWindow.lblDescription.text = self.objSelectedParking.strParkingDescription; infoWindow.lblAddress.text = self.objSelectedParking.strParkingAddress; infoWindow.lblPhone.text = self.objSelectedParking.strParkingPhone; infoWindow.imageViewParking.image = [UIImage imageNamed:@"parking_image_sample.jpg"]; float offset = anchorSize * M_SQRT2; self.actionOverlayCalloutView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, infoWindowWidth, infoWindowHeight - offset/2)]; [self.actionOverlayCalloutView setBackgroundColor:[UIColor clearColor]]; self.actionOverlayCalloutView.layer.cornerRadius = 5; self.actionOverlayCalloutView.layer.masksToBounds = YES; UIButton *hiddenCloseButton = [[UIButton alloc] initWithFrame:CGRectMake((infoWindow.viewContainer.frame.origin.x + infoWindow.viewContainer.frame.size.width - 30), 10, 20, 20)]; [hiddenCloseButton addTarget:self action:@selector(hiddenCloseButtonClickedInInfowindow:) forControlEvents:UIControlEventTouchUpInside]; [self.actionOverlayCalloutView addSubview:hiddenCloseButton]; UIButton *hiddenDirectionButton = [[UIButton alloc] initWithFrame:CGRectMake((infoWindow.lblAddress.frame.origin.x + infoWindow.lblAddress.frame.size.width + 5), (infoWindow.lblAddress.frame.origin.y - 15), 25, 25)]; [hiddenDirectionButton addTarget:self action:@selector(hiddenDirectionButtonClickedInInfowindow:) forControlEvents:UIControlEventTouchUpInside]; [self.actionOverlayCalloutView addSubview:hiddenDirectionButton]; UIButton *hiddenInfoButton = [[UIButton alloc] initWithFrame:CGRectMake((infoWindow.innerContainerView.frame.origin.x + infoWindow.imageViewParking.frame.origin.x + infoWindow.imageViewParking.frame.size.width + 20), (infoWindow.innerContainerView.frame.origin.y + 25), 25, 25)]; [hiddenInfoButton addTarget:self action:@selector(hiddenInfoButtonClickedInInfowindow:) forControlEvents:UIControlEventTouchUpInside]; [self.actionOverlayCalloutView addSubview:hiddenInfoButton]; UIButton *hiddenScheduleButton = [[UIButton alloc] initWithFrame:CGRectMake((infoWindow.innerContainerView.frame.origin.x + infoWindow.verticalLineSeperatorView.frame.origin.x + infoWindow.verticalLineSeperatorView.frame.size.width + 10), (infoWindow.innerContainerView.frame.origin.y + 25), 25, 25)]; [hiddenScheduleButton addTarget:self action:@selector(hiddenScheduleButtonClickedInInfowindow:) forControlEvents:UIControlEventTouchUpInside]; [self.actionOverlayCalloutView addSubview:hiddenScheduleButton]; [infoWindow addSubview:self.actionOverlayCalloutView]; CLLocationCoordinate2D anchor = [_mapView.selectedMarker position]; CGPoint point = [_mapView.projection pointForCoordinate:anchor]; point.y -= _mapView.selectedMarker.icon.size.height + offset/2 + (infoWindowHeight - offset/2)/2; self.actionOverlayCalloutView.center = point; [_mapView addSubview:self.actionOverlayCalloutView]; return infoWindow; } return nil; } -(void)mapView:(GMSMapView *)pMapView didChangeCameraPosition:(GMSCameraPosition *)position { if (pMapView.selectedMarker != nil && self.actionOverlayCalloutView.superview) { float anchorSize = 0.5f; float infoWindowHeight = 250.0f; CLLocationCoordinate2D anchor = [_mapView.selectedMarker position]; CGPoint point = [_mapView.projection pointForCoordinate:anchor]; float offset = anchorSize * M_SQRT2; point.y -= _mapView.selectedMarker.icon.size.height + offset/2 + (infoWindowHeight - offset/2)/2; point.y = point.y - 10; //PRATIK GUJARATI CODE TO ADJUST HEIGHT AND Y VALUE OF TRANSPARENT OVERLAY VIEW self.actionOverlayCalloutView.center = point; } else { [self.actionOverlayCalloutView removeFromSuperview]; } } - (void)mapView:(GMSMapView *)mapView didTapAtCoordinate:(CLLocationCoordinate2D)coordinate { [self.actionOverlayCalloutView removeFromSuperview]; } - (void)observeValueForKeyPath:(NSSsortingng *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { if ([keyPath isEqualToSsortingng:@"mapView.selectedMarker"]) { if (!_mapView.selectedMarker) { [self.actionOverlayCalloutView removeFromSuperview]; } } } 
  1. Créez une sous-vue que vous souhaitez afficher dans infoWindow.

  2. Définir le cadre de la sous-vue est égal au cadre de la vue infoWindow.

     subView = [[[NSBundle mainBundle] loadNibNamed:@"viewName" owner:self options:nil] objectAtIndex:0]; [subView setFrame:infoview.frame]; [self.mapview addSubview:subView];