Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
向iPhone MapView添加多个注释的速度很慢_Iphone_Annotations_Android Mapview - Fatal编程技术网

向iPhone MapView添加多个注释的速度很慢

向iPhone MapView添加多个注释的速度很慢,iphone,annotations,android-mapview,Iphone,Annotations,Android Mapview,我有一个代码,它获取一个位置的标题和地址,然后从谷歌地图csv获取坐标,然后添加注释。它可以工作,但当我想一次添加50个或更多注释时,它会冻结30-40秒,然后显示注释,所以我想知道的是,我有没有搞砸内存管理,这就是为什么它这么慢,或者其他什么原因?我能加快速度吗 代码如下: - (void) addAnnotation: (NSString*) annoTitle: (NSString*) annoAddress { NSString *address = annoAddress;

我有一个代码,它获取一个位置的标题和地址,然后从谷歌地图csv获取坐标,然后添加注释。它可以工作,但当我想一次添加50个或更多注释时,它会冻结30-40秒,然后显示注释,所以我想知道的是,我有没有搞砸内存管理,这就是为什么它这么慢,或者其他什么原因?我能加快速度吗

代码如下:

- (void) addAnnotation: (NSString*) annoTitle: (NSString*) annoAddress
{
    NSString *address = annoAddress;

    NSString *urlString = [NSString stringWithFormat:@"http://maps.google.com/maps/geo?q=%@&output=csv", [address stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
    NSString *locationString = [NSString stringWithContentsOfURL:[NSURL URLWithString:urlString]];
    NSArray *listItems = [locationString componentsSeparatedByString:@","];

    float langcoord = [[listItems objectAtIndex:2] floatValue];
    float longcoord = [[listItems objectAtIndex:3] floatValue];

    CLLocationCoordinate2D coord = CLLocationCoordinate2DMake(langcoord, longcoord);

    // Create an instance of MapPoint with the current data
    Annotation *annotation = [[Annotation alloc] initWithCoordinate:coord title:annoTitle];

    // Add it to the map view
    [mapView addAnnotation:annotation];

    // MKMapView retains its annotations, so we can release it
    [annotation release];
}

以下方法用于MapKit上的多针

-(void)viewWillAppear:(BOOL)animated {

    NSArray *AS=[NSArray arrayWithArray:[reports objectAtIndex:0]];
    for (int i=0; i<[AS count]; i++) {
            Place* home = [[[Place alloc] init] autorelease];
home.name = [[AS objectAtIndex:i] valueForKey:@"comments"];
            home.latitude = [[[AS objectAtIndex:i] valueForKey:@"latitude"]floatValue];
            home.longitude = [[[AS objectAtIndex:i] valueForKey:@"longitude"]floatValue];
valueForKey:@"latitude"]floatValue],[[[AS objectAtIndex:i] valueForKey:@"longitude"]floatValue]];

            PlaceMark* from = [[[PlaceMark alloc] initWithPlace:home] autorelease];
            [mapView addAnnotation:from];
}
    [self centerMap];

    [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
}
-(void)视图将显示:(BOOL)动画{
NSArray*AS=[NSArray arrayWithArray:[报告对象索引:0]];
对于(int i=0;i maxLon)
maxLon=当前位置.坐标.经度;
if(currentLocation.coordinate.longitude
在这里定义多重注释

- (MKAnnotationView *)mapView:(MKMapView *)map viewForAnnotation:(id <MKAnnotation>)annotation
{

    if (annotation == mapView.userLocation)
        return nil;

    MKPinAnnotationView *pin = (MKPinAnnotationView *) [mapView dequeueReusableAnnotationViewWithIdentifier: @"asdf"];

    if (pin == nil)
        pin = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier: @"asdf"] autorelease];
    else
        pin.annotation = annotation;
        pin.userInteractionEnabled = YES;
        UIButton *disclosureButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
        [disclosureButton setFrame:CGRectMake(0, 0, 30, 30)];

        pin.rightCalloutAccessoryView = disclosureButton;
        pin.pinColor = MKPinAnnotationColorRed;
        pin.animatesDrop = YES;
        [pin setEnabled:YES];
        [pin setCanShowCallout:YES];
        return pin;
}
-(MKAnnotationView*)地图视图:(MKMapView*)地图视图注释:(id)注释
{
if(注释==mapView.userLocation)
返回零;
MKPinAnnotationView*引脚=(MKPinAnnotationView*)[mapView出列可重用注释视图,标识符:@“asdf”];
如果(引脚==零)
pin=[[MKPinAnnotationView alloc]initWithAnnotation:annotation重用标识符:@“asdf”]自动释放];
其他的
pin.annotation=注释;
pin.userInteractionEnabled=是;
UIButton*DispositionButton=[UIButton Button类型:UIButtonTypedTailDisposition];
[披露按钮设置框:CGRectMake(0,0,30,30)];
pin.rightCalloutAccessoryView=披露按钮;
pin.pinColor=MKPinAnnotationColorRed;
pin.animatesDrop=是;
[引脚设置已启用:是];
[pin设置CanShowCallout:是];
回位销;
}

以下方法用于MapKit上的多针

-(void)viewWillAppear:(BOOL)animated {

    NSArray *AS=[NSArray arrayWithArray:[reports objectAtIndex:0]];
    for (int i=0; i<[AS count]; i++) {
            Place* home = [[[Place alloc] init] autorelease];
home.name = [[AS objectAtIndex:i] valueForKey:@"comments"];
            home.latitude = [[[AS objectAtIndex:i] valueForKey:@"latitude"]floatValue];
            home.longitude = [[[AS objectAtIndex:i] valueForKey:@"longitude"]floatValue];
valueForKey:@"latitude"]floatValue],[[[AS objectAtIndex:i] valueForKey:@"longitude"]floatValue]];

            PlaceMark* from = [[[PlaceMark alloc] initWithPlace:home] autorelease];
            [mapView addAnnotation:from];
}
    [self centerMap];

    [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
}
-(void)视图将显示:(BOOL)动画{
NSArray*AS=[NSArray arrayWithArray:[报告对象索引:0]];
对于(int i=0;i maxLon)
maxLon=当前位置.坐标.经度;
if(currentLocation.coordinate.longitude
在这里定义多重注释

- (MKAnnotationView *)mapView:(MKMapView *)map viewForAnnotation:(id <MKAnnotation>)annotation
{

    if (annotation == mapView.userLocation)
        return nil;

    MKPinAnnotationView *pin = (MKPinAnnotationView *) [mapView dequeueReusableAnnotationViewWithIdentifier: @"asdf"];

    if (pin == nil)
        pin = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier: @"asdf"] autorelease];
    else
        pin.annotation = annotation;
        pin.userInteractionEnabled = YES;
        UIButton *disclosureButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
        [disclosureButton setFrame:CGRectMake(0, 0, 30, 30)];

        pin.rightCalloutAccessoryView = disclosureButton;
        pin.pinColor = MKPinAnnotationColorRed;
        pin.animatesDrop = YES;
        [pin setEnabled:YES];
        [pin setCanShowCallout:YES];
        return pin;
}
-(MKAnnotationView*)地图视图:(MKMapView*)地图视图注释:(id)注释
{
if(注释==mapView.userLocation)
返回零;
MKPinAnnotationView*引脚=(MKPinAnnotationView*)[mapView出列可重用注释视图,标识符:@“asdf”];
如果(引脚==零)
pin=[[MKPinAnnotationView alloc]initWithAnnotation:annotation重用标识符:@“asdf”]自动释放];
其他的
pin.annotation=注释;
pin.userInteractionEnabled=是;
UIButton*DispositionButton=[UIButton Button类型:UIButtonTypedTailDisposition];
[披露按钮设置框:CGRectMake(0,0,30,30)];
pin.rightCalloutAccessoryView=披露按钮;
pin.pinColor=MKPinAnnotationColorRed;
pin.animatesDrop=是;
[引脚设置已启用:是];
[pin设置CanShowCallout:是];
回位销;
}

现在,当我尝试打开应用程序并加载50条注释时,它会崩溃。
stringWithContentsOfURL
方法是同步的,将阻塞UI,直到完成为止。如果在循环中调用此方法,UI将被阻塞很长时间。这里有两种选择:当我尝试打开应用程序并加载50条注释时,它会崩溃。
stringWithContentsOfURL
方法是同步的,将阻塞UI直到完成。如果在循环中调用此方法,UI将被阻塞很长时间。这里有几个选择:和