[英]SingleTapOnMap method not calling in iphone
I am using below piece of code using to interact with MBTiles. 我正在使用下面的代码与MBTiles进行交互。 But singleTapOnMap method is not calling when i run it on iphone. 但是,当我在iPhone上运行时,singleTapOnMap方法未调用。 I also added Trailer which is working on TileMill, but not on iPhone. 我还添加了可在TileMill上运行的Trailer,但不适用于iPhone。 Whether i have gone wrong anywhere? 我是否在任何地方出了错?
//ViewController.h //ViewController.h
@interface ViewController : UIViewController<RMMapViewDelegate>
@end
//ViewController.m //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;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.