0
我有一個使用Google地圖包的應用程序。該接口在STMapView.h文件中定義:使用Google地圖包
@interface STMapView : GMSMapView
我想用我的STMapView.m觀,使我的標記反應,點擊,所以我也把這個功能:
-(BOOL) mapView:(GMSMapView *) mapView didTapMarker:(GMSMarker *)marker
{
NSLog(@"WHY IS THIS NOT WORKING");
return YES;
}
但是,標記只顯示他們的信息,當我點擊它們時,didTapMarker函數從不使用,因爲NSLog沒有打印到輸出。我需要在別處定義函數嗎? 此外,一旦我得到了響應點擊的功能,如何讓它響應一個小的彈出視圖或傳遞信息中的標記的新視圖?
UPDATE:
STMapView.h
#import <GoogleMaps/GoogleMaps.h>
@interface STMapView : GMSMapView
- (void) updateShuttlesOnMap:(NSMutableData *) shuttleData;
@end
STMapView.m
#import "STMapView.h"
#import "STShuttleMarker.h"
#import "STNetworkManager.h"
#import <Foundation/Foundation.h>
@interface STMapView()
// This is where we will hold all our shuttles
@property (strong, nonatomic) NSMutableDictionary *shuttleMarkers;
// Used privately to add the shuttle stop icons to the map
- (void) addShuttleStopsToMap;
@end
@implementation STMapView
// Perform initial map setup as a View
- (id)initWithFrame:(CGRect)frame {
// First run the super-class init
self = [super initWithFrame:frame];
// Then do our setup if we actually have an object
if (self) {
// Start with room for 6 shuttles. Unsure if initial capacity helps performance or not.
self.shuttleMarkers = [[NSMutableDictionary alloc] initWithCapacity:6];
// We will handle the location stuff ourself.
self.myLocationEnabled = NO;
// Nice visuals
self.mapType = kGMSTypeHybrid;
// Move it to an initial location
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:33.613341
longitude:-84.496
zoom:16.5];
self.camera = camera;
//[self addShuttleStopsToMap];
[self addPickupToMap];
}
return self;
}
標記被在.m文件一個單獨的函數以後加入。下面是該代碼的小大塊:
for (NSDictionary *shuttleStopMarker in shuttleStops) {
// Setup a set of coordinates to use for the marker
double mlat = [(NSNumber *)[shuttleStopMarker objectForKey:@"lat" ] doubleValue];
double mlong = [(NSNumber *)[shuttleStopMarker objectForKey:@"long"] doubleValue];
CLLocationCoordinate2D markerLocation = CLLocationCoordinate2DMake(mlat, mlong);
// Grab the meta data to use for the marker
NSString *shuttleStopName = (NSString *)[shuttleStopMarker objectForKey:@"name"];
NSString *shuttleStopDescription = (NSString *)[shuttleStopMarker objectForKey:@"description"];
// Create this marker with a position, title, and snippet/description
GMSMarker *marker = [GMSMarker markerWithPosition: markerLocation];
marker.title = shuttleStopName;
marker.snippet = shuttleStopDescription;
marker.icon = [UIImage imageNamed:@"PassengerImage"];
//[marker.map setSelectedMarker:marker];
// Now add it to the map.
marker.map = self;
}
你是如何分配一個委託給'STMapView'? – 2014-10-17 09:15:40
@AnthonyKong STMapView作爲常規UIView元素,具有一些特定的增強功能。 – Becksters 2014-10-17 09:29:36
@AnthonyKong你究竟是什麼意思?像我的STViewController是什麼樣的? – Becksters 2014-10-17 09:30:59