Ios SingleTapOnMap方法未在iphone中调用
我正在使用下面的代码与MBTiles交互。但当我在iphone上运行singleTapOnMap方法时,它并没有调用。我还添加了一个拖车,它正在TileMill上工作,但在iPhone上没有。我是否出了什么差错 //ViewController.hIos SingleTapOnMap方法未在iphone中调用,ios,objective-c,iphone,ios7,mapbox,Ios,Objective C,Iphone,Ios7,Mapbox,我正在使用下面的代码与MBTiles交互。但当我在iphone上运行singleTapOnMap方法时,它并没有调用。我还添加了一个拖车,它正在TileMill上工作,但在iPhone上没有。我是否出了什么差错 //ViewController.h @interface ViewController : UIViewController<RMMapViewDelegate> @end @界面ViewController:UIViewController @结束 //ViewCo
@interface ViewController : UIViewController<RMMapViewDelegate>
@end
@界面ViewController:UIViewController
@结束
//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.
}
-(void)viewDidLoad
{
RMMBTilesSource*offlineSource=[[RMMBTilesSource alloc]initwithtilestreesource:@“mbtiles”类型的“MYMAP”;
RMMapView*mapView=[[RMMapView alloc]initWithFrame:self.view.bounds和TileSource:offlineSource];
mapView.zoom=2;
mapView.autoresizingMask=UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
mapView.adjustTilesForRetinaDisplay=YES;//这些瓷砖不是专门为视网膜设计的,所以要使它们清晰可见
[self.view addSubview:mapView];
}
#布拉格标记-
-(void)singleTapOnMap:(RMMapView*)地图视图位于:(CGPoint)点
{
[地图视图删除注释];
RMMapBoxSource*source=(RMMapBoxSource*)mapView.tileSource;
NSLog(@“您点击了%f,%f”,[mapView像素坐标:点].纬度[mapView像素坐标:点].经度);
if([source conformsToProtocol:@protocol(RMInteractiveSource)]&&[source supportsInteractivity])
{
NSString*formattedOutput=[源formattedOutputOfType:rmInteractiveSourceOutputTypeStreamer
点:点
inMapView:mapView];
if(formattedOutput&&[formattedOutput length])
{
//从内容中解析国家名称
//
NSUInteger startOfCountryName=[formattedOutput rangeOfString:@“”]。位置+[@”“长度];
NSUInteger endOfCountryName=[formattedOutput rangeOfString:@“”]。位置;
NSString*countryName=[格式化输出子字符串WithRange:NSMakerRange(startOfCountryName,endOfCountryName-startOfCountryName)];
//从内容中解析标志图像
//
NSUInteger StartOffFlagImage=[formattedOutput rangeOfString:@“base64”,位置+[@“base64”,长度];
NSUTEGER endOfFlagImage=[formattedOutput rangeOfString:@“\”style”];
UIImage*flagImage=[UIImage imageWithData:[NSData dataFromBase64String:[formattedOutput substringWithRange:NSMakeRange(startOfFlagImage,endOfFlagImage)]];
RMANotation*annotation=[RMANotation annotation WithMapView:mapView坐标:[mapView像素坐标:点]和标题:countryName];
annotation.userInfo=flagImage;
[地图视图添加注释:注释];
[地图视图选择注释:注释动画:是];
}
}
}
-(RMMapLayer*)地图视图:(RMMapView*)地图视图图层注释:(RMANotation*)注释
{
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=是;
返回标记;
}
-(无效)未收到记忆警告
{
[超级记忆警告];
//处置所有可以重新创建的资源。
}
您必须分配代理协议:
mapView.delegate = self;
viewDidLoad中缺少
mapView.delegate=self;