0
아래 코드를 사용하여 MBTiles와 상호 작용합니다. 하지만 iphone에서 실행할 때 singleTapOnMap 메서드가 호출되지 않습니다. 나는 TileMill에서 작업하는 Trailer를 추가했지만 iPhone에서는 작동하지 않습니다. 나는 어디에서든지 잘못 갔는가?SingleTapOnMap 메서드가 iphone에서 호출하지 않습니다.
//ViewController.h
@interface ViewController : UIViewController<RMMapViewDelegate>
@end
//ViewController.m
- (void)viewDidLoad
{
RMMBTilesSource *offlineSource = [[RMMBTilesSource alloc] initWithTileSetResource:@"MYMAP" ofType:@"mbtiles"];
RMMapView *mapView = [[RMMapView alloc] initWithFrame:self.view.bounds andTilesource:offlineSource];
mapView.zoom = 2;
mapView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
mapView.adjustTilesForRetinaDisplay = YES; // these tiles aren't designed specifically for retina, so make them legible
[self.view addSubview:mapView];
}
#pragma mark -
- (void)singleTapOnMap:(RMMapView *)mapView at:(CGPoint)point
{
[mapView removeAllAnnotations];
RMMapBoxSource *source = (RMMapBoxSource *)mapView.tileSource;
NSLog(@"You tapped at %f, %f", [mapView pixelToCoordinate:point].latitude, [mapView pixelToCoordinate:point].longitude);
if ([source conformsToProtocol:@protocol(RMInteractiveSource)] && [source supportsInteractivity])
{
NSString *formattedOutput = [source formattedOutputOfType:RMInteractiveSourceOutputTypeTeaser
forPoint:point
inMapView:mapView];
if (formattedOutput && [formattedOutput length])
{
// parse the country name out of the content
//
NSUInteger startOfCountryName = [formattedOutput rangeOfString:@"<strong>"].location + [@"<strong>" length];
NSUInteger endOfCountryName = [formattedOutput rangeOfString:@"</strong>"].location;
NSString *countryName = [formattedOutput substringWithRange:NSMakeRange(startOfCountryName, endOfCountryName - startOfCountryName)];
// parse the flag image out of the content
//
NSUInteger startOfFlagImage = [formattedOutput rangeOfString:@"base64,"].location + [@"base64," length];
NSUInteger endOfFlagImage = [formattedOutput rangeOfString:@"\" style"].location;
UIImage *flagImage = [UIImage imageWithData:[NSData dataFromBase64String:[formattedOutput substringWithRange:NSMakeRange(startOfFlagImage, endOfFlagImage)]]];
RMAnnotation *annotation = [RMAnnotation annotationWithMapView:mapView coordinate:[mapView pixelToCoordinate:point] andTitle:countryName];
annotation.userInfo = flagImage;
[mapView addAnnotation:annotation];
[mapView selectAnnotation:annotation animated:YES];
}
}
}
- (RMMapLayer *)mapView:(RMMapView *)mapView layerForAnnotation:(RMAnnotation *)annotation
{
RMMarker *marker = [[RMMarker alloc] initWithMapBoxMarkerImage:@"embassy"];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 50, 32)];
imageView.contentMode = UIViewContentModeScaleAspectFit;
imageView.image = annotation.userInfo;
marker.leftCalloutAccessoryView = imageView;
marker.canShowCallout = YES;
return marker;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
당신이 누락을'mapView.delegate = self;'viewDidLoad에서 –