iPhone Mapkit- 주석 좌표 및지도 업데이트
-
18-09-2019 - |
문제
이 튜토리얼을 사용하여 Mapkit을 응용 프로그램에 통합합니다.http://iphonebcit.wordpress.com/iphone-map-kit-tutorial/
CLLocationCoordinate2D coordinate;
coordinate.latitude = 49.2802;
coordinate.longitude = -123.1182;
NSUInteger count = 1;
for(int i = 0; i < 10; i++) {
CGFloat latDelta = rand()*.035/RAND_MAX - .02;
CGFloat longDelta = rand()*.03/RAND_MAX - .015;
CLLocationCoordinate2D newCoord = {coordinate.latitude+latDelta, coordinate.longitude+longDelta};
MapDemoAnnotation* annotation = [[MapDemoAnnotation alloc] initWithCoordinate:newCoord andID:count++];
[mapView addAnnotation:annotation];
[annotation release];
}
그리고
- (MKAnnotationView *)mapView:(MKMapView *)mapViewLocal viewForAnnotation:(id <MKAnnotation>)annotation {
MKPinAnnotationView *pinView = (MKPinAnnotationView*)[mapViewLocal dequeueReusableAnnotationViewWithIdentifier:@"Pin"];
if(pinView == nil) {
pinView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"Pin"];
pinView.pinColor = MKPinAnnotationColorPurple;
pinView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
pinView.animatesDrop = YES;
pinView.canShowCallout = YES;
} else {
pinView.annotation = annotation;
}
return pinView;
}
따라서 핀은 맵에 무작위로 설정됩니다. 내 응용 프로그램에서 좌표가 변경됩니다. 주석의 좌표를 어떻게 변경하여지도에서 업데이트 될 수 있습니까?
아는 사람 있나요?
해결책
iPhone SDK 3.X에서는 핀 주석을 제거하고 다시 설정해야합니다. 지도에 많은 주석이 있다면 그리 좋지 않습니다.
화면에있는 핀 주석을 갱신/갱신하도록 더 좋게 만들려고 노력합니다. 따라서 사용자가 뉴욕으로 확대되면 샌프란시스코 나 사용자가 볼 수없는 다른 핀 주석이 없습니다. 따라서 성능이 훨씬 나아질 것입니다.
아마도 미래에 이것은 가능할 것입니다. 나는 희망한다 :-)
다른 팁
이 튜토리얼은 표시 할지도보기를 가져 오는 것만으로도 다른 것은 없습니다. 더 큰 튜토리얼이 필요합니다. 나는 이것이 유용하다고 생각했다 :
http://blog.objectgraph.com/index.php/2009/04/02/iphone-sdk-30-playing-map-kit/
아마도 당신이해야 할 일은 맵의 모든 주석을 루프하고 제거한 다음 데이터 배열을 통해 반복하여 주석을 다시 추가하는 것입니다. 당신은 그것에 대해 더 영리하고 데이터 배열을 통해 루프를 통해지도에 동일한 위도/경도가있는 핀이 있는지 확인하지만 그 방식은 더 복잡해집니다.
지금은 주석을 달고 있기 때문에 빠른 테스트를했습니다. 컴파일러 경고를 받으므로 지원되지 않을 수 있습니다. 그러나 그것은 작동합니다.
조정 속성을 쓸 수 있도록 사용자 정의 mkannotation 클래스를 만드십시오.
@property (nonatomic, readwrite) CLLocationCoordinate2D coordinate;
그런 다음 원하는 이벤트 나 간격에서 다음과 같은 것을 사용하여 좌표를 변경하십시오.
CLLocation *loc=[[CLLocation alloc] initWithLatitude:55.0 longitude:17.0];
annotation.coordinate=loc.coordinate;
[loc release];