0
먼저 모든지도의지도에 핀 만 표시하는지도 페이지를 실행하고 있습니다. 나는지도 위에 단 하나의 핀만을 달고 있었고, 25 개 이상의 핀을 넣은 후에는지도 페이지에 매우 느리게 밀어 넣었습니다. 이 프로세스에서 지금하고있는 일은 앱이 핀 위치의 모든 데이터를로드하기 만하면 (목표 출력에서 볼 수 있듯이) 다음 화면으로 이동합니다. 그러니 제발 내 문제가 되겠습니까?온라인 데이터로드가 매우 느림 어렵습니다.
- (void)viewDidLoad
{
[super viewDidLoad];
self.title = @"";
self.navigationItem.title = @"Mek";
response = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:@"http://kalkatawi.com/mapLocation.php"]];
if(response!=nil) {
NSError *parseError = nil;
jsonArray = [NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingAllowFragments error:&parseError];
jsonArray1 = [[NSMutableArray alloc] init];
jsonArray2 = [[NSMutableArray alloc] init];
jsonArray3 = [[NSMutableArray alloc] init];
for(int i=0;i<[jsonArray count];i++)
{
name = [[jsonArray objectAtIndex:i] objectForKey:@"name"];
longitude = [[jsonArray objectAtIndex:i] objectForKey:@"longitude"];
latitude = [[jsonArray objectAtIndex:i] objectForKey:@"latitude"];
[jsonArray1 addObject:name];
[jsonArray2 addObject:longitude];
[jsonArray3 addObject:latitude];
self.locationMap.delegate = self; //set delegate before adding annotations
CLLocationCoordinate2D annotationCoord;
for (int i=0; i < [jsonArray count]; i++)
{
NSDictionary *annotationDictionary = [jsonArray objectAtIndex:i];
name = [annotationDictionary objectForKey:@"name"];
annotationCoord.latitude
= [[annotationDictionary objectForKey:@"longitude"] doubleValue];
annotationCoord.longitude
= [[annotationDictionary objectForKey:@"latitude"] doubleValue];
MKPointAnnotation *annotationPoint = [[MKPointAnnotation alloc] init];
annotationPoint.coordinate = annotationCoord;
annotationPoint.title = name;
annotationPoint.subtitle = [NSString stringWithFormat:@"%f %f", annotationPoint.coordinate.latitude, annotationPoint.coordinate.longitude];
[self.locationMap addAnnotation:annotationPoint];
//------------------------//
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(annotationPoint.coordinate, 50000, 50000);
[self.locationMap setRegion:[self.locationMap regionThatFits:region] animated:YES];
locationManager = [[CLLocationManager alloc] init];
locationManager.distanceFilter = kCLDistanceFilterNone;
locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters;
[locationManager startUpdatingLocation];
lat = locationManager.location.coordinate.latitude;
lon = locationManager.location.coordinate.longitude;
}
}
}
else {
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"You are not connected to internet" message:@"Please check the internet connection" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
}
}
- (MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:(id <MKAnnotation>)annotation
{
MKAnnotationView *pinView = nil;
if(annotation != locationMap.userLocation)
{
static NSString *defaultPinID = @"myPin";
pinView = (MKAnnotationView *)[locationMap dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
if (pinView == nil)
pinView = [[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:defaultPinID] autorelease];
pinView.image = [UIImage imageNamed:@"pinpinpin.png"];
pinView.canShowCallout = YES;
pinView.enabled = YES;
UIButton *infoButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
pinView.rightCalloutAccessoryView = infoButton;
}
return pinView;
}
문제는 주 스레드에서 수행하는 것입니다. 이러한 히브 작업은 다른 백그라운드 스레드에서 수행해야하며 기본 UI 흐름을 차단하지 않아야합니다. –
'jsonArray'를 통해 두 개의 중첩 된'for i' 루프가있는 것처럼 보입니다. 왜? 'jsonArray'에 25 개의 항목이 있다면, 명백한 이유없이 25 * 25 = 625 반복을 의미합니다. 또한, 왜 당신은 내부 루프 _ 반복마다'CLLocationManager'를 할당하고 시작합니까? 루프 외부에서 위치 관리자 _once_를 할당하고 시작하십시오. _each_ 반복에서'setRegion' 또한 불필요합니다 (루프 외부에서 _once_합니다). – Anna
@AnnaKarenina 루프 외부에서'CLLocationManger'와'setRegion'을 가져 왔습니다. 나는 그것이 훨씬 빠르다고 느낍니다. 'jsonArray' 루프에서 두 개가 아닌 하나의 루프를 사용하라고 말하고 있습니까? 저에게 알려주세요. 고마워 –