I used the function
self.view = mapView;
button to find the location worked fine, but I did not like the fact that the card was full-screen windows, and I replaced
self.view = mapView_; on mapView_.frame = CGRectMake (0, 0, 400, 600); [self.view addSubview: mapView_];
then disappeared button Mylocation and the inscription Google. how can I get the search button in place and whether the automatic search the user on the map? I mean, once the user has opened the card immediately on the map to determine its location.
[GMSServices provideAPIKey:#"#####"];
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:59.93
longitude:30.35
zoom:9];
mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];
mapView_.settings.compassButton = YES;
mapView_.settings.myLocationButton = YES;
mapView_.frame = CGRectMake(0, 0, 400, 600);
[self.view addSubview:mapView_];
mapView_.myLocationEnabled = YES;
As Much as I have used GMSMApview, It scales to the assigned views Frame, try adding a Subview and then with a specific frame to your main View, and then assign the GMSMapview to the SubVIew added,
Or, If you only want to place a button, then I would simply place it on NAvigation BAr as a bar button Item, More Easy, more space allotted to the map, for user,
Related
I have a DetailViewController that is to be shown when user taps a marker on the mapView_. Initially I load the VC and set it hidden, and when the user would tap a marker, I would load values in the VC and show it. But it is not happening. Here's my code.
#property (strong, nonatomic) GMSMapView *mapView;
- (void)viewDidLoad
{
[super viewDidLoad];
_whisperDetailView.hidden = YES;
[_whisperDetailView initlize];
_whisperDetailView.viewController = self;
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.86
longitude:151.20
zoom:6];
mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];
mapView_.myLocationEnabled = YES;
self.view = mapView_;
}
- (BOOL)mapView:(GMSMapView *)mapView didTapMarker:(GMSMarker *)marker
{
_detailView.whisper = marker.userData;
_detailView.hidden = NO;
return YES;
}
Storyboard snapshot:
Funny thing is I was using Mapbox before and was doing exact same thing in its didSelectAnnotation function and everything was working great. I recently had to switch to Google Map and now its not working.
Any help is appreciated. Thanks.
Okay I've got it working now! Posting the answer for anyone else stuck in same situation:
I changed the way I was adding my mapView_. instead of assigning self.view = mapView in viewDidLoad, I inserted mapView as a subview to my main view, like this:
mapView_ = [GMSMapView mapWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height) camera:camera];
[self.view insertSubview:mapView_ atIndex:0];
And alas! everything works like a charm now! When I tap a marker, my DetailViewController shows with proper sizes and as I set it up in storyboard.
I've created a test project, it has a UIViewController. a UIView (myView) declared as xib it has an image and 3 buttons
I'm adding the UIView programmatically to UIViewController and add a swipe gesture to UIView in the viewDidLoad method of UIViewController
swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(swipeAction:)];
swipeRight.direction = UISwipeGestureRecognizerDirectionRight;
[myView addGestureRecognizer:swipeRight];
[self.view addSubview:myView];
All works well.
Then I add the google maps to the UIViewcontroller again in 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 = YES;
self.view = 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_;
first problem: myview is not showing --> I move the code of adding UIView to viewDidAppear.
now the view is seen the buttons respond but the swipe gesture is not working
any ideas?
The view, in which you added your myView, is getting replaced by your map view due to this line: self.view = mapView_; Hence, your view is not visible.
You should add your map view as a subview instead. Try replacing that line with [self.view addSubview:mapView_]
I created a viewcontroller with Google maps , but I have no need to insert the card in full size viewcontroller, and I got it ( the new view I added a class GMSMapView) but I need to put this map markers . Example of my marker
CLLocationCoordinate2D position2 = CLLocationCoordinate2DMake(59.957069, 30.323013);
GMSMarker *london2 = [GMSMarker markerWithPosition:position2];
london2.title = #"my office";
london2.snippet = #"description";
london2.map = mapView_;
This is my code
- (void)viewDidLoad {
[super viewDidLoad];
self.mapView_.mapType = kGMSTypeNormal;
self.mapView_.settings.compassButton = YES;
self.mapView_.settings.myLocationButton = YES;
self.mapView_.delegate = self;
[GMSServices provideAPIKey:#"###"];
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.86
longitude:151.20
zoom:1];
mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];
mapView_.myLocationEnabled = YES;
mapView_.settings.compassButton = YES;
mapView_.settings.myLocationButton = YES;
//self.view = mapView_;
GMSMarker *london2 = [GMSMarker markerWithPosition:position2];
london2.title = #"my office";
london2.snippet = #"description";
london2.map = mapView_;
Question - if I add a line self.view = mapView_; the card is reflected on the whole screen with the right markers to me , if I remove , it is reflected without markers , but my desired size - how to fix it ( make a map of the desired size and markers )
You can change your self.view = mapView_;
to the following code:
mapView.frame = CGRectMake(YOUR_MAP_X, YOUR_MAP_Y, YOUR_MAP_WIDTH, YOUR_MAP_HEIGHT);
[self.view addSubview:mapView_];
Your mapView_ will be a subview of your main UIView, instead of occupying the entire screen.
I am trying to load places inside Google Map View for iOS6.
How to set the frame for the Map ?
Currently it is fullscreen
-(void)loadView {
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:10.00989
longitude:76.316142
zoom:15];
mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];
self.view = mapView_;
}
I tried by creating a new (small) view inside the current view and add map inside that,but at that time the page is not getting loaded.It shows a full black screen
-(void)loadView {
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:10.00989
longitude:76.316142
zoom:15];
mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];
[self.view Addsubview:newView];
self.newView = mapView_;
}
Finally found the solution.
Remove the loadview method, and put the following code in the view did load method:
-(void)viewDidLoad{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.86
longitude:151.20
zoom:6];
mapView_ = [GMSMapView mapWithFrame:CGRectMake(0, 0, 100, 100) camera:camera];
[self.view addSubview:mapView_];
// Create a GMSCameraPosition that tells the map to display the
// coordinate -33.86,151.20 at zoom level 6.
mapView_.myLocationEnabled = YES;
// 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_;
}
Try
mapView_ = [GMSMapView mapWithFrame:self.view.bounds camera:camera];
[self.view addSubview:mapView_];
if you put into loadView it wont have a view.. the xib isn't even loaded...
put it in viewDidLoad
and do
mapView_ = [GMSMapView mapWithFrame:self.view.bounds camera:camera];
[self.view addSubview:mapView_];
Check the declaration #property for GMSMapView , if it is weak property then make it strong.
#property (strong,nonatomic)GMSMapView *mapView;
By removing func loadView from my code fixed my problem
override func loadView() {
}
Or by putting this line of code inside the loadView
override func loadView() {
self.view = GMSMapView(frame: UIScreen.main.bounds)
}
I've attempted to use the code from the GoogleMapsSDKDemos to resize the mapview to a smaller rectangle on the screen, but it doesn't appear to have any effect. Here is my code:
mapView = [[GMSMapView alloc] initWithFrame:CGRectZero];
mapView.camera = [GMSCameraPosition cameraWithLatitude:38.98549782690282
longitude:-76.94636067188021
zoom:17];
self.view = [[UIView alloc] initWithFrame:CGRectZero];
mapView.autoresizingMask =
UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
mapView.frame = self.view.frame;
mapView.clipsToBounds = YES;
mapView.myLocationEnabled = YES;
mapView.settings.tiltGestures = NO;
mapView.settings.zoomGestures = NO;
mapView.frame = CGRectMake(0,0, 10, 25);
[self.view addSubview:self.mapView];
That second-to-last line seemingly should limit the MapView to just a small square, but it still takes up the entire screen.
I would try something like this:
GMSCameraPosition* camera = [GMSCameraPosition
cameraWithLatitude: 38.98549782690282
longitude: -76.94636067188021
zoom: 17];
GMSMapView* mapView =
[GMSMapView mapWithFrame: GRectMake(0,0, 10, 25) camera: camera];
Note that the comments on the GMSMapView class in GMSMapView.h say:
This class should not be instatiated directly, instead it must be
created with [GMSMapServices mapWithFrame:camera:]
Try this to add the map to the top of view:
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:latitude
longitude:longitude
zoom:10];
mapView_ = [GMSMapView mapWithFrame:CGRectMake(0,0, width, height) camera:camera];
mapView_.delegate = self;
mapView_.myLocationEnabled = YES;
[self.view addSubview:mapView_];