Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS Google Maps SDK, Can't listen to GMSMarker tap event

I'm stuck with GoogleMaps SDK for iOS...
I want to add some features when I tap on a GMSMarker on my Google Map, but it doesn't work. Is there something wrong?

FirstController.h

#import <UIKit/UIKit.h>
#import <GoogleMaps/GoogleMaps.h>
#import <CoreLocation/CoreLocation.h>
#import "sqlite3.h"

@interface FirstViewController : UIViewController <CLLocationManagerDelegate,
                                                  GMSMapViewDelegate>
{
    sqlite3 *db;
}

FirstController.m

[...]

-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
    camera = [GMSCameraPosition cameraWithLatitude:newLocation.coordinate.latitude longitude:newLocation.coordinate.longitude zoom:(12)];
    mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];
    mapView_.myLocationEnabled = YES;

    for(GMSMarker *currentMarker in _locationMarkers)
    {
        currentMarker.map = mapView_;
    }

    self.view = mapView_;
}


-(BOOL) mapView:(GMSMapView *) mapView didTapMarker:(GMSMarker *)marker
{
    NSLog(@"try");
    return YES;
}
like image 260
Michele Avatar asked Oct 03 '13 15:10

Michele


1 Answers

I think you might need this, after you create the map:

mapView_.delegate = self;
like image 124
Saxon Druce Avatar answered Sep 22 '22 04:09

Saxon Druce