1

Я разработал карту google, в которой я показываю местоположение пользователя atm. Я добавил индикатор активности для анимации, когда мое приложение получает информацию, и оно должно прекратиться, когда оно появилось.Индикатор активности не удаляется из представления googlemap

Для этого я написал следующий код. Индикатор активности отображается, но он не удаляется. Пожалуйста, помогите мне сделать это.

#import "ViewController.h" 
#import <GoogleMaps/GoogleMaps.h> 


@interface ViewController()<GMSMapViewDelegate> 
{ 
    NSUserDefaults *latitudess; 
    NSUserDefaults *longitudess; 
    GMSMapView *mapView_; 
    UIView *viewForSlider; 
    UILabel *labelToShowCurrentRadiusValue; 
    NSMutableData *urldata; 
    NSInteger *j; 
    UIActivityIndicatorView *spinner; 

} 

@end 

@implementation ViewController 

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    mapView_ = [[GMSMapView alloc] init]; 

    GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:22.595769 
                  longitude:88.263639 
                   zoom:12]; 


    mapView_ = [GMSMapView mapWithFrame:CGRectMake(0.0, 0.0, self.view.frame.size.width, self.view.frame.size.height) camera:camera]; 
    mapView_.delegate=self; 
    mapView_.settings.myLocationButton = YES; 
    mapView_.myLocationEnabled = YES; 
    [self.view addSubview:mapView_]; 



    GMSMarker *marker = [[GMSMarker alloc] init]; 
    marker.position = CLLocationCoordinate2DMake(22.595769, 88.263639); 
    marker.title = @"Howrah"; 
    marker.snippet = @"Kolkata"; 
    marker.map = mapView_; 



    viewForSlider = [[UIView alloc]initWithFrame:CGRectMake(0, self.view.frame.size.height - 62.0 , self.view.frame.size.width, 62.0)]; 
    viewForSlider.backgroundColor = [UIColor colorWithWhite:0.9 alpha:0.9]; 

    [self.view addSubview:viewForSlider]; 



    labelToShowCurrentRadiusValue =[[UILabel alloc]initWithFrame:CGRectMake(0, 8.0, viewForSlider.frame.size.width, 20.0)]; 
    labelToShowCurrentRadiusValue.backgroundColor=[UIColor clearColor]; 
    [labelToShowCurrentRadiusValue setFont:[UIFont systemFontOfSize:15.0]]; 
    labelToShowCurrentRadiusValue.textAlignment=NSTextAlignmentCenter; 
    labelToShowCurrentRadiusValue.textColor=[UIColor colorWithRed:84.0/255.0 green:84.0/255.0 blue:84.0/255.0 alpha:1.0]; 
    [viewForSlider addSubview:labelToShowCurrentRadiusValue]; 


    [self startUserTracking]; 
    [self displayAtm]; 



spinner = [[UIActivityIndicatorView alloc]initWithFrame:CGRectMake(135,140,50,50)]; 
    spinner.color = [UIColor blueColor]; 
    [spinner startAnimating]; 
     [self.view addSubview:spinner]; 


} 

- (void)didReceiveMemoryWarning { 
    [super didReceiveMemoryWarning]; 


-(void)startUserTracking 
{ 


    if (mapView_.observationInfo == nil) 
    { 
     [mapView_ addObserver:self 
        forKeyPath:@"myLocation" 
         options:NSKeyValueObservingOptionNew 
         context:NULL]; 


     dispatch_async(dispatch_get_main_queue(), ^{ 
      mapView_.myLocationEnabled = YES; 
     }); 
    } 
} 

- (void)observeValueForKeyPath:(NSString *)keyPath 
         ofObject:(id)object 
         change:(NSDictionary *)change 
         context:(void *)context 
{ 



    CLLocation *location = [change objectForKey:NSKeyValueChangeNewKey]; 

    mapView_.camera = [GMSCameraPosition cameraWithTarget:location.coordinate 
                zoom:15]; 

    labelToShowCurrentRadiusValue.text = [NSString stringWithFormat:@"%f , %f", location.coordinate.latitude, location.coordinate.longitude]; 
    latitudess=[NSUserDefaults standardUserDefaults]; 
    longitudess=[NSUserDefaults standardUserDefaults]; 
    [latitudess setFloat:location.coordinate.latitude forKey:@"LATITUDE"]; 
    [latitudess setFloat:location.coordinate.longitude forKey:@"LONGITUDE"]; 
    [latitudess synchronize]; 

    @try { 
     [mapView_ removeObserver:self forKeyPath:@"myLocation"]; 
    } @catch(id exception){ 

    } 

} 



-(void)displayAtm 
{ 

    latitudess=[NSUserDefaults standardUserDefaults]; 

    float retrievedlat=[latitudess floatForKey:@"LATITUDE"]; 
    float retrievedlong=[latitudess floatForKey:@"LONGITUDE"]; 
    NSLog(@"detail=%f",retrievedlat); 



    NSString *urlforrequest=[NSString stringWithFormat:@"https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=%f,%f&radius=500&types=atm&name=atm&key=*******",retrievedlat,retrievedlong]; 
    NSURL *finalurl=[NSURL URLWithString:urlforrequest]; 



    urldata=[[NSMutableData alloc]initWithContentsOfURL:finalurl]; 
    NSError *error; 
    id jsonresults=[NSJSONSerialization JSONObjectWithData:urldata options:kNilOptions error:&error]; 

    NSArray *datarray= [jsonresults objectForKey:@"results"]; 
    for (int i=0; i<datarray.count; i++) 
    { 
     GMSMarker *marker=[[GMSMarker alloc]init]; 
     NSDictionary *geometryretrieved=[[datarray valueForKey:@"geometry"]objectAtIndex:i]; 
     NSDictionary *coordinatesretrieved=[geometryretrieved valueForKey:@"location"]; 
     marker.position=CLLocationCoordinate2DMake([[coordinatesretrieved objectForKey:@"lat"] doubleValue], [[coordinatesretrieved objectForKey:@"lng"]doubleValue]); 
     marker.title=[[datarray valueForKey:@"name"]objectAtIndex:i]; 
     marker.map=mapView_; 

     [spinner removeFromSuperview]; 


    } 


} 

Заранее спасибо.

ответ

0

изменение в виде сделал загрузка звонок этот способ последний после дисплей прядильщик в [self displayAtm];

- (void)viewDidLoad 
{ 
    [self startUserTracking]; 
    // [self displayAtm]; 



spinner = [[UIActivityIndicatorView alloc]initWithFrame:CGRectMake(135,140,50,50)]; 
    spinner.color = [UIColor blueColor]; 
    [spinner startAnimating]; 
     [self.view addSubview:spinner]; 

[self displayAtm]; 

} 
+0

no sir, не удаляя индикатор и не отображая его на карте. –

+0

spinner не удаляет becz, когда вы показываете spinner, тогда вы не вызывали displayatm in viewdidload –

+0

Я сделал ошибку, что я не устанавливал правильную комбинацию цветов, а время загрузки очень быстро, поэтому его отображение не отображается –

Смежные вопросы