2013-10-03 74 views
5

我一直在使用適用於iOS的GoogleMaps SDK ...
我想添加一些功能,當我點擊Google Map上的GMSMarker時,沒有工作。 有什麼問題嗎?iOS Google Maps SDK,無法收聽GMSMarker的點擊事件

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

回答

18

我想你創建地圖後,你可能需要這個,:

mapView_.delegate = self; 
+0

工作,謝謝!我不小心把這些代碼放在錯誤的方法中! – Michele