如何在地圖中顯示圖像而不是針腳。到目前爲止,我只能添加引腳。 .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 - 來自NSDictionary的地圖上的多個針腳
- 3. MapKit和自定義類
- 4. 利用MapKit渲染自定義圖像 - iOS
- 5. ios使用MapKit中的故事板自定義註釋視圖
- 6. 如何實現自定義動畫天氣MapKit疊加 - iOS,Swift
- 7. 我可以將自定義Google地圖導入iOS MapKit嗎?
- 8. 自定義腳本的ImageMagick(回形針?)
- 9. 如何將自定義引腳添加到iPhone MapKit?
- 10. Mapkit具有自定義圖像和細節的引腳陣列?
- 11. MapKit路由自定義引腳和標註
- 12. 使用iPhone的自定義地圖MapKit
- 13. MapKit:添加自定義標註
- 14. 在地圖上放棄多個針腳給定座標Mapkit iPhone
- 15. 自定義UITableViewCell iOS
- 16. IOS自定義UIImagePickerController
- 17. MKMapViewAnnotation來自自定義圖像的圖像針對多個針腳不同
- 18. iOS:爲什麼我無法使用mapkit顯示自定義註釋引腳圖像?
- 19. 爲什麼我無法使用mapkit顯示自定義註釋引腳圖像?
- 20. 我們如何將標籤貼在MapKit的自定義引腳上?
- 21. 針對iOS呼叫警報的自定義設計
- 22. OpenCv - iOS MapKit衝突
- 23. IOS 4.3.2 MapKit註釋
- 24. 實現MapKit iOS Xcode
- 25. iOS MapKit:選定的MKAnnotation座標
- 26. 自定義UISlider點子ios
- 27. iOS自定義UItableviewcell部分
- 28. iOS自定義對話框
- 29. 自定義登錄Simperium IOS
- 30. 自定義UIButton圖像iOS
一點點搜索走一段很長的路要走:) http://stackoverflow.com/questions/4579397/iphone-mapkit-adding-custom-image-and-pins-to-annotations也:HTTP:/ /stackoverflow.com/questions/7124028/change-pin-design –