2015-09-24 4 views
0

Я использую GoogleMap SDK в iOS для отображения текущего местоположения пользователя. Карта Google отображается на моем представлении, но маркер не отображается. Я не знаю, что я делаю неправильно здесь.маркер не отображается на карте google

Вот мой код

#import <GoogleMaps/GoogleMaps.h> 
@interface firstViewController() { 
    // GMSMapView *mapView_; 
    IBOutlet GMSMapView *mapView_; 
} 
@end 

@implementation firstViewController 

- (void)viewDidLoad { 
    [super viewDidLoad]; 

    // Create a GMSCameraPosition that tells the map to display the 
    // coordinate -33.86,151.20 at zoom level 6. 
    GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.86 
                  longitude:151.20 
                   zoom:6]; 
    mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera]; 
    mapView_.myLocationEnabled = NO; 
    [self.view addSubview: mapView_]; 


    // Creates a marker in the center of the map. 
    GMSMarker *marker = [[GMSMarker alloc] init]; 
    marker.position = CLLocationCoordinate2DMake(-33.86, 151.20); 
    marker.title = @"Sydney"; 
    marker.snippet = @"Australia"; 
    marker.map = mapView_; 
} 
+0

чек здесь, если вам нужно Swift https://stackoverflow.com/questions/15417811/cannot-put-a-google-maps-gmsmapview-in-a-subview-of-main-main-view/ 48517389 # 48517389 –

ответ

2

Почему вы настройки вашей карты с CGRectZero кадра ??

mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera]; 
mapView_.myLocationEnabled = NO; 
[self.view addSubview: mapView_]; 

Карта будет недоступна, если вы установите ее в CGRectZero. Итак, сначала попробуйте сделать свой mapView видимым, предоставив ему другой фрейм.

+0

ваш прием :) –

0

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

- (void)getCamerasWithNortheast:(CLLocationCoordinate2D)neCoord southwest:(CLLocationCoordinate2D)swCoord fromDutation:(int)fromDuration 
{ 
    NSString* urlString = nil; 
    if(fromDuration == 0) 
    { 
     urlString = [NSString stringWithFormat:@"/api/v1/camera?bounds=%f,%f,%f,%f&limit=100", swCoord.longitude, swCoord.latitude, neCoord.longitude, neCoord.latitude]; 
    } 
    else 
    { 
     urlString = [NSString stringWithFormat:@"/api/v1/camera?bounds=%f,%f,%f,%f&limit=100&fromDuration=%d", swCoord.longitude, swCoord.latitude, neCoord.longitude, neCoord.latitude,fromDuration]; 
    } 

    _loadingCameras = YES; 
    dispatch_async(dispatch_get_main_queue(), ^{ 
     //[_activitySpinner startAnimating]; 
    }); 

    HttpRequest* request = [HttpRequest requestWithRelativePath:urlString]; 
    [HttpResponse processAsynchronousRequest:request onCompletion:^(HttpResponse* response) 
    { 
     dispatch_async(dispatch_get_main_queue(), ^{ 
      NSMutableArray* newCameras = [[NSMutableArray alloc] init]; 
      newCameras = [response.responseJSON objectForKey:@"cameras"]; 
      for (NSDictionary* camera in newCameras) 
      { 
       LiveCameraAnnotation* annotation = [[LiveCameraAnnotation alloc] initWithJSON:camera]; 
       GMSMarker *marker = [[GMSMarker alloc] init]; 
       marker.position = annotation.coordinate; 
       marker.title = annotation.camera.name; 
       marker.appearAnimation = kGMSMarkerAnimationPop; 
       marker.icon = [GMSMarker markerImageWithColor:[UIColor purpleColor]]; 
       marker.userData = @{@"annotation":annotation}; 
       marker.map = mapView_; 

       // Check if launched with camera 
       if (_cameraData && [annotation.camera.uuid isEqualToString:_cameraData.uuid]){ 
        [mapView_ setSelectedMarker:marker]; 
        _cameraData = nil; 
       } 
       marker = nil; 
      } 
      _loadingCameras = NO; 
     }); 
    }]; 
} 
Смежные вопросы