Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.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
iOS:加载GMSMapView会消耗内存负载并降低FPS(每秒帧数)速率_Ios_Google Maps_Memory Management_Frame Rate_Gmsmapview - Fatal编程技术网

iOS:加载GMSMapView会消耗内存负载并降低FPS(每秒帧数)速率

iOS:加载GMSMapView会消耗内存负载并降低FPS(每秒帧数)速率,ios,google-maps,memory-management,frame-rate,gmsmapview,Ios,Google Maps,Memory Management,Frame Rate,Gmsmapview,我已经创建了一个谷歌地图视图,在那里我放置了一些注释,并在加载时放置它们,但是当我不断更改相机视图时,内存消耗会变得太高,大约200MB。FPS速率也从30降至5或6。我的应用程序只会崩溃。我怎样才能释放那个记忆?这是我的代码,当我移动相机角度时 - (void)mapView:(GMSMapView *)mapview didChangeCameraPosition:(GMSCameraPosition *)position { [self updateCenterOfScreenM

我已经创建了一个谷歌地图视图,在那里我放置了一些注释,并在加载时放置它们,但是当我不断更改相机视图时,内存消耗会变得太高,大约200MB。FPS速率也从30降至5或6。我的应用程序只会崩溃。我怎样才能释放那个记忆?这是我的代码,当我移动相机角度时

- (void)mapView:(GMSMapView *)mapview didChangeCameraPosition:(GMSCameraPosition *)position 
{
    [self updateCenterOfScreenMarker:position.target];
}

- (void)updateCenterOfScreenMarker:(CLLocationCoordinate2D)coordinate {
       [self updateMarkers:currentLocation];
    CLLocation * centerOfGreen = [self getLocationCenterOfGreen];
    if (centerOfGreen) {
        CLLocation * currentCamera = [[CLLocation alloc] initWithLatitude:coordinate.latitude longitude:coordinate.longitude];
        CLLocationDistance distance = [currentCamera distanceFromLocation:centerOfGreen];
        distanceFromCameraToGolfer = [currentCamera distanceFromLocation:currentLocation];
        [currentCamera release];

        distanceFromCameraToCenterOfGreen = distance;
        if (isYards) {
            distanceFromCameraToCenterOfGreen *= METERS_TO_YARDS;
            distanceFromCameraToGolfer *= METERS_TO_YARDS;
        }

        if (centerMarker) {
            centerMarker.map = nil; // You can remove a marker from the map by setting your GMSMarker's map property to nil.
            [centerMarker release];
            centerMarker = nil;
            headingLabel.text=@"";
            headingLabel=nil;
            headingLabel.text=nil;
            headingLabel2.text=@"";
            headingLabel2=nil;
            headingLabel2.text=nil;
            headingLabel3.text=@"";
            headingLabel3=nil;
            headingLabel3.text=nil;
            headingLabel4.text=@"";
            headingLabel4=nil;
            headingLabel4.text=nil;
            centerMarker.icon =nil;
        }


        if (mapView) {
//            centerMarker = [GMSMarker markerWithPosition:coordinate];
            headingLabel.text=@"";
            headingLabel2.text=@"";
            headingLabel3.text=@"";
            headingLabel4.text=@"";

            if(distanceFromCameraToGolfer >= 1000)
            {
                headingLabel = [[UILabel alloc] initWithFrame:CGRectMake(40, 180, 120, 30)];
                headingLabel2 = [[UILabel alloc] initWithFrame:CGRectMake(160, 180, 40, 30)];
                headingLabel3 = [[UILabel alloc] initWithFrame:CGRectMake(200, 180, 20, 30)];
                headingLabel4 = [[UILabel alloc] initWithFrame:CGRectMake(225, 180, 70, 30)];
            }
            else
            {
                headingLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 180, 100, 30)];
                headingLabel2 = [[UILabel alloc] initWithFrame:CGRectMake(125, 180, 40, 30)];
                headingLabel3 = [[UILabel alloc] initWithFrame:CGRectMake(170, 180, 20, 30)];
                headingLabel4 = [[UILabel alloc] initWithFrame:CGRectMake(195, 180, 70, 30)];
            }
            headingLabel.font=[UIFont fontWithName:@"Roboto-Bold" size:30];
            headingLabel2.font=[UIFont fontWithName:@"Roboto-Regular" size:30];
            headingLabel3.font=[UIFont fontWithName:@"Roboto-Light" size:30];
            headingLabel4.font=[UIFont fontWithName:@"Roboto-Bold" size:30];

            headingLabel.textColor=[UIColor whiteColor];
            headingLabel2.textColor=[UIColor whiteColor];
            headingLabel3.textColor=[UIColor yellowColor];
            headingLabel4.textColor=[UIColor whiteColor];

            headingLabel.textAlignment=NSTextAlignmentRight;
            headingLabel2.textAlignment=NSTextAlignmentCenter;
            headingLabel3.textAlignment=NSTextAlignmentCenter;
            headingLabel4.textAlignment=NSTextAlignmentLeft;


            headingLabel.text=nil;
            headingLabel2.text=nil;
            headingLabel3.text=nil;
            headingLabel4.text=nil;

//            centerMarker.title = nil;
//            centerMarker.snippet = nil;
//            centerMarker.groundAnchor = CGPointMake(0.5, 0.5);
            str=@"";
            str = [NSString stringWithFormat:@"%d",distanceFromCameraToGolfer];
            str2=@"";

            NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];
            NSString * units = [defaults objectForKey:PREFERENCE_KEY_UNITS];
            if ([units isEqualToString:@"yards"]) {
                str2 = [NSString stringWithFormat:@"Yd"]; 
            }
            else
            {
                str2 = [NSString stringWithFormat:@" m"];
            }

            str3=@"";
            str3 = [NSString stringWithFormat:@"/"];
            str4=@"";
            str4 = [NSString stringWithFormat:@"%d", distanceFromCameraToCenterOfGreen];

            if([str4 intValue]>=0 && [str4 intValue]<=14)
            {
                headingLabel.hidden=YES;
                headingLabel2.hidden=YES;
                headingLabel3.hidden=YES;
                headingLabel4.hidden=YES;
            }

            headingLabel.text=str;
            headingLabel2.text=str2;
            headingLabel3.text=str3;
            headingLabel4.text=str4;
            [mapView addSubview:headingLabel];
            [mapView addSubview:headingLabel2];
            [mapView addSubview:headingLabel3];
            [mapView addSubview:headingLabel4];
//            centerMarker.icon = [self addText:[UIImage imageNamed:@"grid.png"] text:@""  red:255 green:255 blue:255];
//            centerMarker.map = mapView;
//            centerMarker.tappable=NO;
            [centerMarker retain];
            [headingLabel release];
            [headingLabel2 release];
            [headingLabel3 release];
            [headingLabel4 release];

        } // mapView

    }

}
在上面的代码中,标题标签是显示从当前位置到相机位置距离的标签。 下面是内存消耗和FPS的图像

你可以试试, 此委托方法中的更改:

- (void)mapView:(GMSMapView *)mapView idleAtCameraPosition:(GMSCameraPosition *)position{
    [self updateCenterOfScreenMarker:position.target];
}

这可能有助于释放内存