Ios 未从Google地图视图中删除活动指示器
我开发了一个谷歌地图,其中显示了atm附近的用户位置。我已经添加了一个活动指示器,当我的应用程序获取信息时,它会显示动画,当它获取信息时,它会停止 为此,我编写了以下代码。我的活动指示器正在显示,但未删除。请帮我这么做Ios 未从Google地图视图中删除活动指示器,ios,google-maps,google-maps-sdk-ios,uiactivityindicatorview,Ios,Google Maps,Google Maps Sdk Ios,Uiactivityindicatorview,我开发了一个谷歌地图,其中显示了atm附近的用户位置。我已经添加了一个活动指示器,当我的应用程序获取信息时,它会显示动画,当它获取信息时,它会停止 为此,我编写了以下代码。我的活动指示器正在显示,但未删除。请帮我这么做 #import "ViewController.h" #import <GoogleMaps/GoogleMaps.h> @interface ViewController ()<GMSMapViewDelegate> { NSUserD
#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];
}
}
#导入“ViewController.h”
#进口
@界面视图控制器()
{
相对性;
n连续性*纵向性;
GMSMapView*地图视图;
UIView*viewForSlider;
UILabel*labelToShowCurrentRadiusValue;
NSMutableData*urldata;
NSInteger*j;
UIActivityIndicatorView*微调器;
}
@结束
@实现视图控制器
-(无效)viewDidLoad{
[超级视图下载];
映射视图=[[GMSMapView alloc]init];
GMSCameraPosition*摄像机=[GMSCameraPosition摄像机,纬度:22.595769
经度:88.263639
缩放:12];
mapView_979;=[GMSMapView mapWithFrame:CGRectMake(0.0,0.0,self.view.frame.size.width,self.view.frame.size.height)摄像机:摄像机];
mapView_.delegate=self;
mapView_979;.settings.myLocationButton=是;
mapView_u2;.myLocationEnabled=是;
[self.view addSubview:mapView_];
GMSMarker*标记=[[GMSMarker alloc]init];
marker.position=CLLocationCoordinate2DMake(22.595769,88.263639);
marker.title=@“Howrah”;
marker.snippet=@“加尔各答”;
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-WithWhite: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颜色与红色:84.0/255.0绿色:84.0/255.0蓝色:84.0/255.0 alpha:1.0];
[viewForSlider addSubview:labelToShowCurrentRadiusValue];
[自启动跟踪];
[自动显示ATM];
微调器=[[UIActivityIndicatorView alloc]initWithFrame:CGRectMake(135140,50,50)];
spinner.color=[UIColor blueColor];
[spinner startAnimating];
[self.view addSubview:spinner];
}
-(无效)未收到记忆警告{
[超级记忆警告];
-(无效)startUserTracking
{
如果(地图视图观察信息==nil)
{
[地图视图\添加观察者:自我
分叉路径:@“myLocation”
选项:NSKeyValueObservingOptionNew
上下文:NULL];
dispatch\u async(dispatch\u get\u main\u queue()^{
mapView_u2;.myLocationEnabled=是;
});
}
}
-(void)observeValueForKeyPath:(NSString*)键路径
ofObject:(id)对象
更改:(NSDictionary*)更改
上下文:(void*)上下文
{
CLLocation*location=[ChangeObjectForkey:NSKeyValueChangeNewKey];
mapView_979;.camera=[GMSCameraPosition cameraWithTarget:location.coordinate
缩放:15];
labelToShowCurrentRadiusValue.text=[NSString stringWithFormat:@“%f,%f”,location.coordinate.latitude,location.coordinate.longitude];
纬度=[NSUserDefaults standardUserDefaults];
longitudes=[NSUserDefaults standardUserDefaults];
[latitudess setFloat:location.coordinate.latitude forKey:@“latitude”];
[latitudess setFloat:location.coordinate.longitude-forKey:@“longitude”];
[纬度同步];
@试一试{
[mapView_uuveObserver:自分叉路径:@“myLocation”];
}@catch(id异常){
}
}
-(作废)自动取款机
{
纬度=[NSUserDefaults standardUserDefaults];
float retrievedlat=[纬度floatForKey:@“纬度];
float retrievedlong=[纬度floatForKey:@“经度”];
NSLog(@“详细信息=%f”,检索LAT);
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];
n错误*错误;
id jsonresults=[NSJSONSerialization JSONObjectWithData:urldata选项:针织错误:&错误];
NSArray*datarray=[jsonresults objectForKey:@“results”];
对于(int i=0;i视图中的更改didload在[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];
}
在[self displayAtm]中的display spinner之后最后一次调用此方法的视图更改didload
- (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];
}
不,先生,它没有移除指示器,它仍然显示在地图上。spinner没有移除becz当您使用spinner show时,您没有在ViewDidLoad中调用displayatm。我犯了一个错误,我没有设置正确的颜色组合,加载时间非常快,因此它没有显示IR,您能帮我一下吗他是CLLocationManager,但我还是得到了我的答案,如果我使用CLLocationManager,可能会造成什么不同。不,先生,它没有移除指示器,并且它仍然显示在地图上。微调器没有移除,因为当你的微调器显示时,你没有在ViewDidLoad中调用displayatm。我犯了一个错误,我没有设置正确的颜色组合和加载时间非常快,因此它不会显示IR,您能帮我指出我没有使用CLLocationManager,但我仍然得到了我的答案,如果我使用CLLocationManager,可能会造成什么不同。