首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Google在iOS中删除多个Pins

Google在iOS中删除多个Pins
EN

Stack Overflow用户
提问于 2014-09-02 05:11:23
回答 1查看 1.6K关注 0票数 0

我正在开发一个应用程序,在这个应用程序中,我需要用用户当前的位置显示Google并检索地址。我已经实现了这个部分,它正在工作,现在我需要使用google在那个地方找到最近的餐厅。我已经把它们整合在一起了,它正在向我展示最近的餐馆。不过,我需要在那家餐厅里挂上别针。我使用GMSMarker来显示单个引脚,但是我需要在获得信息后显示多个引脚。下面是我的源代码。请帮助放下多个引脚。

代码语言:javascript
复制
- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    CLLocationCoordinate2D coordinate;

    locationManager = [[CLLocationManager alloc] init];
    locationManager.delegate = self;
    locationManager.desiredAccuracy = kCLLocationAccuracyBest;
    locationManager.distanceFilter = kCLDistanceFilterNone;
    [locationManager startUpdatingLocation];
    currentLocation = [locationManager location];
    coordinate = [currentLocation coordinate];

    GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:coordinate.latitude longitude:coordinate.longitude zoom:15];

    GMSMapView *mapView = [GMSMapView mapWithFrame:CGRectMake(0, 0, 320, 300) camera:camera];
    mapView.delegate = self;

    // Creates a marker in the center of the map.
    GMSMarker *marker = [[GMSMarker alloc] init];
    marker.position = CLLocationCoordinate2DMake(coordinate.latitude, coordinate.longitude);
    marker.title = @"Current Location";
    marker.snippet = @"Test";
    marker.map = mapView;

    [self.view addSubview:mapView];
}


- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
    currentLocation = [locations objectAtIndex:0];
    [locationManager stopUpdatingLocation];
    CLGeocoder *geocoder = [[CLGeocoder alloc] init] ;
    [geocoder reverseGeocodeLocation:currentLocation completionHandler:^(NSArray *placemarks, NSError *error)
     {
         if (!(error))
         {
             CLPlacemark *placemark = [placemarks objectAtIndex:0];
             NSLog(@"\nCurrent Location Detected\n");
             NSLog(@"placemark %@",placemark);
             NSString *locatedAt = [[placemark.addressDictionary valueForKey:@"FormattedAddressLines"] componentsJoinedByString:@", "];
             NSString *Address = [[NSString alloc]initWithString:locatedAt];
             NSString *Area = [[NSString alloc]initWithString:placemark.locality];
             NSString *Country = [[NSString alloc]initWithString:placemark.country];
             NSString *CountryArea = [NSString stringWithFormat:@"%@, %@", Area,Country];
             NSLog(@"%@",CountryArea);
             NSLog(@"%@",Address);
         }
         else
         {
             NSLog(@"Geocode failed with error %@", error);
             NSLog(@"\nCurrent Location Not Detected\n");
             //return;
         }
     }];
}


-(IBAction)nearbyPlaces:(id)sender {

    NSString *str=[NSString  stringWithFormat:@"https://maps.googleapis.com/maps/api/place/search/json?location=%f,%f&radius=5000&types=%@&sensor=true&key=%@",currentLocation.coordinate.latitude,currentLocation.coordinate.longitude,@"restaurant",@"AIzaSyB0jFNjBtUlr-zbhiCm-xduYR1YkDMV1Fo"];
    NSLog(@"\n\n URL %@",str);
    NSURL *strurl = [NSURL URLWithString:[str stringByReplacingOccurrencesOfString:@"|" withString:@"%7C"]];

    NSURLRequest *urlRequest = [NSURLRequest requestWithURL:strurl];
    NSOperationQueue *queue = [[NSOperationQueue alloc] init];

    [NSURLConnection sendAsynchronousRequest:urlRequest queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {

        if ([data length] > 0 && error == nil) {

            self.view = mapView_;
            id result = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
            if ([result isKindOfClass:[NSMutableArray class]])
            {
                NSLog(@"\n\n.......This is Mutable Array");
            }
            else
            {
                if ([[result objectForKey:@"results"] count] > 0) {

                    NSLog(@">>>>>>>> dict keys :%lu \nFull Address : %@\n LatLong : %@ \n total result : %lu", (unsigned long)[[result objectForKey:@"results"] count],[[result objectForKey:@"results"]valueForKey:@"vicinity"],[[[result objectForKey:@"results"]valueForKey:@"geometry"]valueForKey:@"location"],(unsigned long)[[result objectForKey:@"results"]count]);

                    for (int i=0; i<[[result objectForKey:@"results"] count]; i++) {
                        NSLog(@"%@",[[[result objectForKey:@"results"]objectAtIndex:i]valueForKey:@"name"]);
                        NSLog(@"%@",[[[result objectForKey:@"results"]objectAtIndex:i]valueForKey:@"vicinity"]);
                        NSLog(@"%@",[[[result objectForKey:@"results"]objectAtIndex:i]valueForKey:@"reference"]);

                        CLLocationCoordinate2D location;
                        location.latitude = [[[[[[result objectForKey:@"results"]objectAtIndex:i]valueForKey:@"geometry"]valueForKey:@"location"] valueForKey:@"lat"]doubleValue];
                        location.longitude = [[[[[[result objectForKey:@"results"]objectAtIndex:i]valueForKey:@"geometry"]valueForKey:@"location"] valueForKey:@"lng"] doubleValue];
                    }
                }
            }
        }
    }];
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-09-02 05:23:52

代码语言:javascript
复制
for (int i=0; i<[youArray count]; i++)
        {            
            CLLocationCoordinate2D position = CLLocationCoordinate2DMake(latitude,longitude);
            GMSMarker *marker = [GMSMarker markerWithPosition:position];
            marker.title = @"Title";
            marker.snippet = @"Subtitle";
            marker.flat=YES;
            marker.map = _mapView_results;
        }

这是我曾经做过的代码。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25616285

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档