Adding Click Event on InfoWindow/Marker in Google Maps SDK for native iOS/objective C

后端 未结 7 2080
无人及你
无人及你 2020-12-05 05:41

Simple Question

I´m working on an App for iOS where I embedded the new Google Map for native iOS. Everything works fine except one problem where I can´t find a propp

相关标签:
7条回答
  • 2020-12-05 05:55
    1. Create one subview which you want to show in infoWindow.

    2. Set frame of subview equals to frame of infoWindow view.

      subView = [[[NSBundle mainBundle] loadNibNamed:@"viewName" owner:self options:nil] objectAtIndex:0]; 
      [subView setFrame:infoview.frame]; 
      [self.mapview addSubview:subView];
      
    0 讨论(0)
  • 2020-12-05 06:00

    get information at google map view information

        func mapView(_ mapView: GMSMapView, didTapInfoWindowOf marker: GMSMarker) {
        print(marker.title!)
        print(marker.snippet!)
    }
    
    0 讨论(0)
  • 2020-12-05 06:02

    1.conform to the GMSMapViewDelegate protocol.

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

    2.set your mapView_ delegate.

    mapView_.delegate = self;
    

    3.implement the GMSMapViewDelegate method

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

    btw, marker.userData is useful. you can set your needed data into it and use it in - mapView:didTapInfoWindowOfMarker:

    0 讨论(0)
  • 2020-12-05 06:04

    Swift 5.1

    You can use GMSMapViewDelegate with:

    mapView.delegate = self
    
    func mapView(_ mapView: GMSMapView, didTapInfoWindowOf marker: GMSMarker) {
            print("InfoView tapped")
    }
    
    0 讨论(0)
  • 2020-12-05 06:07

    a full answer for swift 4

    1. add GMSMapViewDelegate as delegate

    2. set yourmap delegate like this : googlemap.delegate = self

    3. add this func

    func mapView(_ mapView: GMSMapView, didTap marker: GMSMarker) -> Bool 
                {
                   // do something
                    return true
                }
    
    0 讨论(0)
  • 2020-12-05 06:10

    where you adding Map,add

     mapView_.delegate=self; 
    

    then use this

    -(void)mapView:(GMSMapView *)mapView
    didTapInfoWindowOfMarker:(id<GMSMarker>)marker{
    
       //info window tapped
    
    }
    
    0 讨论(0)
提交回复
热议问题