여러 개의 주석이있는지도를 만들고 있는데 어떻게 동적으로 (CoreData에 포함 시켰는지) 알지 못합니다.지도 주석을 동적으로 배치하는 방법은 무엇입니까?
- (void)viewDidLoad {
[super viewDidLoad];
CLLocation *userLoc = mapView.userLocation.location;
CLLocationCoordinate2D userCoordinate = userLoc.coordinate;
NSLog(@"user latitude = %f",userCoordinate.latitude);
NSLog(@"user longitude = %f",userCoordinate.longitude);
mapView.delegate=self;
NSMutableArray* annotations=[[NSMutableArray alloc] init];
CLLocationCoordinate2D theCoordinate1;
theCoordinate1.latitude = 43.82078;
theCoordinate1.longitude = 15.307265;
CLLocationCoordinate2D theCoordinate2;
theCoordinate2.latitude = 44.91035917;
theCoordinate2.longitude = 14.65576172;
MyAnnotation* myAnnotation1=[[MyAnnotation alloc] init];
myAnnotation1.coordinate=theCoordinate1;
[email protected]"Rohan";
[email protected]"in the city";
MyAnnotation* myAnnotation2=[[MyAnnotation alloc] init];
myAnnotation2.coordinate=theCoordinate2;
[email protected]"Vaibhav";
[email protected]"on a Bridge";
[mapView addAnnotation:myAnnotation1];
[mapView addAnnotation:myAnnotation2];
[annotations addObject:myAnnotation1];
[annotations addObject:myAnnotation2];
NSLog(@"%d",[annotations count]);
//[self gotoLocation];//to catch perticular area on screen
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
// Walk the list of overlays and annotations and create a MKMapRect that
// bounds all of them and store it into flyTo.
MKMapRect flyTo = MKMapRectNull;
for (id <MKAnnotation> annotation in annotations) {
NSLog(@"fly to on");
MKMapPoint annotationPoint = MKMapPointForCoordinate(annotation.coordinate);
MKMapRect pointRect = MKMapRectMake(annotationPoint.x, annotationPoint.y, 0, 0);
if (MKMapRectIsNull(flyTo)) {
flyTo = pointRect;
} else {
flyTo = MKMapRectUnion(flyTo, pointRect);
//NSLog(@"else-%@",annotationPoint.x);
}
}
// Position the map so that all overlays and annotations are visible on screen.
mapView.visibleMapRect = flyTo;
UIBarButtonItem* temp=[[UIBarButtonItem alloc] init];
[email protected]"Back";
self.navigationItem.backBarButtonItem=temp;
//[temp release];
}
추신 :
나는 그들이 코드로 고정 퍼 팅 해요 추가 코드가 필요하면 알려주십시오.
감사의 도움을
UPDATE :
Locations.h
...
@interface Locations : NSManagedObject
@property (nonatomic, retain) NSDecimalNumber * lat;
@property (nonatomic, retain) NSDecimalNumber * lon;
...
업데이트 2 : 여기
내가 주석을 퍼 팅있어 예제 코드입니다 "결정된".
http://dl.dropbox.com/u/77033905/stackoverflow/Map.zip
어떻게 배열을 통해이 주석을 추가 할 수 있습니까? (배열의 좌표, 제목, subitle 및지도에 추가합니다.)이 위치를 정의
동적으로 무엇을 의미합니까? –
PHP에서 나는 이것들을 다음과 같이 두었습니다 : $ array [] = $ annotation; 등 – CroiOS
아직도 모른다. 네가 정확히하고 싶은 걸 내버려 둬. –