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