17

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 propper solution for native IOS/ Objective-C neither here nor at google (if there is one please show me and sorry for annoying you)

What I want: I want the User to Click on the Marker that opens the Info Window. After If he clicks or taps on the Info Window it should open a New UIView with further Informations.

How can I do that?

Thanks for advices

Saxon Druce
  • 17,406
  • 5
  • 50
  • 71
Corona
  • 685
  • 1
  • 10
  • 15
  • It's called Annotation Disclosure: http://stackoverflow.com/questions/1433067/adding-an-accessory-view-button-to-the-mkmapview-call-out-annotation – viral Mar 15 '13 at 13:03
  • 6
    the accepted answer is pertinent to Apple MapKit, not Google Maps?! – nikkumang Aug 08 '14 at 03:20
  • yes you are right. And it´s an old answer with an old question anyways :D – Corona Jan 09 '16 at 13:15
  • For googlemap, infowindow is rendered as UIImage, there is no way to add interaction inside the infowindow, this blog solves the problem: http://kevinxh.github.io/swift/custom-and-interactive-googlemaps-ios-sdk-infowindow.html – Kevin He Nov 12 '16 at 02:08

7 Answers7

84

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:

Brian
  • 30,156
  • 15
  • 86
  • 87
2

where you adding Map,add

 mapView_.delegate=self; 

then use this

-(void)mapView:(GMSMapView *)mapView
didTapInfoWindowOfMarker:(id<GMSMarker>)marker{

   //info window tapped

}
user2115266
  • 137
  • 1
  • 12
2

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
            }
Uma Madhavi
  • 4,851
  • 5
  • 38
  • 73
iman kazemayni
  • 1,255
  • 1
  • 19
  • 20
2

Swift 5.1

You can use GMSMapViewDelegate with:

mapView.delegate = self

func mapView(_ mapView: GMSMapView, didTapInfoWindowOf marker: GMSMarker) {
        print("InfoView tapped")
}
Alessandro Ornano
  • 34,887
  • 11
  • 106
  • 133
1

I am using Google Maps SDK for iOS.

I have subclassed uiview to create a custom view "InfoWindow" for infowindow.

add @property (nonatomic,retain) UIView *actionOverlayCalloutView; in your viewcontroller's header file.

- (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:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
if ([keyPath isEqualToString:@"mapView.selectedMarker"]) {
    if (!_mapView.selectedMarker) {
        [self.actionOverlayCalloutView removeFromSuperview];
    }
}
}
Pratik Gujarati
  • 302
  • 2
  • 3
0
  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];
    
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
Dhananjay Patil
  • 442
  • 3
  • 10
0

get information at google map view information

    func mapView(_ mapView: GMSMapView, didTapInfoWindowOf marker: GMSMarker) {
    print(marker.title!)
    print(marker.snippet!)
}
Uma Madhavi
  • 4,851
  • 5
  • 38
  • 73
kiran pm
  • 151
  • 3
  • 3