如何在地圖中顯示圖像而不是針腳。到目前爲止,我只能添加引腳。 .m的示例代碼將非常有幫助,因爲我還是iOS編程的新手。iOS MapKit自定義針腳
16
A
回答
53
#pragma mark -
#pragma mark MKMapView delegate
- (MKAnnotationView *)mapView:(MKMapView *)mapview viewForAnnotation:(id <MKAnnotation>)annotation
{
if ([annotation isKindOfClass:[MKUserLocation class]])
return nil;
static NSString* AnnotationIdentifier = @"AnnotationIdentifier";
MKAnnotationView *annotationView = [mapView dequeueReusableAnnotationViewWithIdentifier:AnnotationIdentifier];
if(annotationView)
return annotationView;
else
{
MKAnnotationView *annotationView = [[[MKAnnotationView alloc] initWithAnnotation:annotation
reuseIdentifier:AnnotationIdentifier] autorelease];
annotationView.canShowCallout = YES;
annotationView.image = [UIImage imageNamed:@"someImage.png"];
UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[rightButton addTarget:self action:@selector(writeSomething:) forControlEvents:UIControlEventTouchUpInside];
[rightButton setTitle:annotation.title forState:UIControlStateNormal];
annotationView.rightCalloutAccessoryView = rightButton;
annotationView.canShowCallout = YES;
annotationView.draggable = YES;
return annotationView;
}
return nil;
}
編輯:
我可以向大家解釋這MKAnnotationView
,但我想你會發現蘋果提供比任何其他來源一個更好的解釋文件。檢查鏈接中的概述部分。
https://developer.apple.com/documentation/mapkit/mkannotationview
6
轉到組織者的Xcode,然後去到文檔和搜索weatherMap它顯示地圖包括註釋圖像的例子。
0
#pragma mark -
#pragma mark MKMapView delegate
-(void)addAllPinsOnMapView
{
MKCoordinateRegion region = mapViewOffer.region;
region.center = CLLocationCoordinate2DMake(12.9752297537231, 80.2313079833984);
region.span.longitudeDelta= 0.1f;
region.span.latitudeDelta= 0.1f;
[mapViewOffer setRegion:region animated:YES];
mapViewOffer.delegate=self;
arrMapPin=[[NSMutableArray alloc] init];
NSArray *name=[[NSArray alloc]initWithObjects:
@"Title1",
@"Title2",
@"Title3", nil];
NSMutableArray *arrCoordinateStr = [[NSMutableArray alloc] initWithCapacity:name.count];
[arrCoordinateStr addObject:@"12.970760345459,80.2190093994141"];
[arrCoordinateStr addObject:@"12.9752297537231,80.2313079833984"];
[arrCoordinateStr addObject:@"12.9788103103638,80.2412414550781"];
for(int i = 0; i < name.count; i++)
{
NSArray *components = [[arrCoordinateStr objectAtIndex:i] componentsSeparatedByString:@","];
double latitude = [components[0] doubleValue];
double longitude = [components[1] doubleValue];
MKPointAnnotation *mapPin = [[MKPointAnnotation alloc] init];
CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(latitude, longitude);
mapPin.title = [name objectAtIndex:i];
mapPin.coordinate = coordinate;
[mapViewOffer addAnnotation:mapPin];
}
}
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:
(MKAnnotationView *)view
{
NSLog(@"%@",view.annotation.title);
NSLog(@"%f",view.annotation.coordinate.latitude);
NSLog(@"%f",view.annotation.coordinate.longitude);
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(calloutTapped:)];
[view addGestureRecognizer:tapGesture];
}
-(void)calloutTapped:(UITapGestureRecognizer *) sender
{
NSLog(@"Callout was tapped");
MKAnnotationView *view = (MKAnnotationView*)sender.view;
id <MKAnnotation> annotation = [view annotation];
if ([annotation isKindOfClass:[MKPointAnnotation class]])
{
//[self performSegueWithIdentifier:@"annotationDetailSegue" sender:annotation];
OfferDetailsViewController *objOfferDetailsViewController = [[OfferDetailsViewController alloc]init];
[self.navigationController pushViewController:objOfferDetailsViewController animated:YES];
}
}
- (MKAnnotationView *)mapView:(MKMapView *)theMapView
viewForAnnotation:(id <MKAnnotation>)annotation
{
MKAnnotationView *pinView = nil;
static NSString *defaultPinID = @"annotationViewID";
pinView = (MKAnnotationView *)[mapViewOffer dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
if (pinView == nil){
pinView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:defaultPinID];
}
pinView.canShowCallout = YES;
pinView.image = [UIImage imageNamed:@"placeholder"];
UIButton *infoButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[infoButton addTarget:self action:@selector(infoButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
pinView.rightCalloutAccessoryView = infoButton;
return pinView;
}
+0
在發佈長代碼片段之前添加一些說明。 –
相關問題
- 1. iOS MapKit針腳側面的自定義標註
- 2. iOS Mapkit自定義標註
- 3. Mapkit中的自定義引腳
- 4. 學習iOS MapKit - 來自NSDictionary的地圖上的多個針腳
- 5. MapKit和自定義類
- 6. MapKit自定義地圖
- 7. MapKit中的自定義地圖樣式
- 8. iOS如何讓MapKit顯示自定義室內地圖?
- 9. ios-mapkit,自定義圖像註釋的奇怪行爲
- 10. 利用MapKit渲染自定義圖像 - iOS
- 11. iOS Mapkit自定義圖像出現2倍大
- 12. 如何實現自定義動畫天氣MapKit疊加 - iOS,Swift
- 13. 我可以將自定義Google地圖導入iOS MapKit嗎?
- 14. ios使用MapKit中的故事板自定義註釋視圖
- 15. 自定義腳本的ImageMagick(回形針?)
- 16. Mapkit具有自定義圖像和細節的引腳陣列?
- 17. MapKit路由自定義引腳和標註
- 18. 如何將自定義引腳添加到iPhone MapKit?
- 19. MapKit註釋的自定義引腳圖像
- 20. iOS,UITableView與自定義頁腳文本和自定義footerview
- 21. MapKit折線自定義縮放?
- 22. Iphone自定義Mapkit註釋圖像
- 23. MapKit:添加自定義標註
- 24. 使用iPhone的自定義地圖MapKit
- 25. 顯示自定義多個針腳顯示針對位置的針腳錯誤
- 26. IOS MapKit引腳不在當前位置
- 27. mapkit中的iOS引腳顏色問題
- 28. 在地圖上放棄多個針腳給定座標Mapkit iPhone
- 29. 自定義標記與服務器imagen在mapkit swift
- 30. IOS自定義UIButton
一點點搜索走一段很長的路要走:) http://stackoverflow.com/questions/4579397/iphone-mapkit-adding-custom-image-and-pins-to-annotations也:HTTP:/ /stackoverflow.com/questions/7124028/change-pin-design –