0
I’m using Google’s Maps API for iOS. I was doing some testing and I set up a UIView
as a subclass of GMSMapView
and kept a pointer for her in ViewController
, getting:
#import <UIKit/UIKit.h>
#import <GoogleMaps/GoogleMaps.h>
#import <CoreLocation/CoreLocation.h>
@interface ViewController : UIViewController<GMSMapViewDelegate, CLLocationManagerDelegate>
{
CLLocationManager *locationManager;
}
@property (strong, nonatomic) IBOutlet GMSMapView *meuMapa;
@end
And I did its implementation in another class, this way:
-(GMSMapView*)criaMapa{
// Create a GMSCameraPosition that tells the map to display the
// coordinate -33.86,151.20 at zoom level 6.
GMSCameraPosition *camera = [GMSCameraPosition
cameraWithLatitude:-22.530351
longitude:-43.071199
zoom:17];
_mapaCriado = [GMSMapView mapWithFrame:CGRectZero camera:camera];
#pragma mark - Coloca Pinos no Mapa
// Uma posição em Niteroi
GMSMarker *marker = [[GMSMarker alloc] init];
marker.position = CLLocationCoordinate2DMake(-22.530303,-43.071033);
marker.title = @"Ponto B";
marker.snippet = @"Detalhes";
marker.map = _mapaCriado;
return _mapaCriado;
}
Getting back in ViewController.m
in the method -(void)viewDidLoad
i get the map that was created in another class:
- (void)viewDidLoad {
CriaMapas mapFact = [[CriaMapas alloc]init];
self.meuMapa = [mapFact criaMapa];
}
But the map is started with nothing, as if there had been no initialization and no creation of Marker.
How could you do this: Create the map in another class and return it to be displayed?
Iboutlet is a Uiview added by the Build Interface, and the Gmsmapview class is assigned to it, so I just assign it the map information in Viewcontroller itself and it works... I thought I could assign a Gmsmapview started on another object to it too.... but is there a way to have a map "factory"? I’ll give you one more search.... Vlw!
– Tiago Amaral
Dude, I did a test just instantiating and passing Marker... and it makes more sense :D. It’s possible to do this with Gmsmarker. Vlw!
– Tiago Amaral
Yes, it is the other way really more practical, since the map has already been created by Builder interface, because there is no need to create twice. Either create it dynamically or by the interface, the after assigns the features and etc.
– Paulo Rodrigues