Iphone App with google maps + UIView does not respond to swipe gestures - ios

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_]

Related

iOS Objective-C Google map shows only on debug when added to a subview

I'm using google maps SDK, first all was working fine but it was shown as a full screen. After adding the map into a subview, the map is no more shown. I added a breakpoint on the IBAction and noticed that after passing:
self.mapView1 = [GMSMapView mapWithFrame:_subview.bounds camera:camera];
the map is shown perfectly in the subview.
Thats my code in IBAction:
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:33.67 longitude:35.55 zoom:12];
self.mapView1 = [GMSMapView mapWithFrame:_subview.bounds camera:camera];
self.mapView1.myLocationEnabled = YES;
[_mapView1 setMinZoom:12 maxZoom:20];
self.mapView1.mapType = kGMSTypeSatellite;
self.mapView1.settings.compassButton = YES;
_mapView1.delegate = self;
[_mapView1 animateToViewingAngle:45];
// Creates a marker in the center of the map.
GMSMarker *marker = [[GMSMarker alloc] init];
marker.position = CLLocationCoordinate2DMake(33.67, 35.55);
marker.title = #"City";
marker.snippet = #"Country";
marker.map = _mapView1;
[_subview addSubview:_mapView1];
thats how i want it to look like
Thanks in advance.
Try this it's working for me.
GMSMapView *customView = [[GMSMapView alloc] initWithFrame:CGRectMake(100, 300, 100, 100)];
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:33.67 longitude:35.55 zoom:12];
customView = [GMSMapView mapWithFrame:customView.bounds camera:camera];
customView.myLocationEnabled = YES;
[customView setMinZoom:12 maxZoom:20];
customView.mapType = kGMSTypeSatellite;
customView.delegate = self;
[customView animateToViewingAngle:45];
// Creates a marker in the center of the map.
GMSMarker *marker = [[GMSMarker alloc] init];
marker.position = CLLocationCoordinate2DMake(33.67, 35.55);
marker.title = #"City";
marker.snippet = #"Country";
marker.map = customView;
[self.view addSubview:customView];
OR
GMSMapView *customView = [[GMSMapView alloc] initWithFrame:CGRectMake(100, 300, 100, 100)];
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:33.67 longitude:35.55 zoom:12];
_mapView = [GMSMapView mapWithFrame:customView.bounds camera:camera];
_mapView.myLocationEnabled = YES;
[_mapView setMinZoom:12 maxZoom:20];
_mapView.mapType = kGMSTypeSatellite;
_mapView.settings.compassButton = YES;
_mapView.delegate = self;
[_mapView animateToViewingAngle:45];
// Creates a marker in the center of the map.
GMSMarker *marker = [[GMSMarker alloc] init];
marker.position = CLLocationCoordinate2DMake(33.67, 35.55);
marker.title = #"City";
marker.snippet = #"Country";
marker.map = _mapView;
[customView addSubview:_mapView];
[self.view addSubview:customView];
Also check your _subview hidden or not.
Since i can't comment, i will use this way to ask you to do some stuff:
1- Add a breankpoint to this line and check _subview.bounds values.
self.mapView1 = [GMSMapView mapWithFrame:_subview.bounds camera:camera];
2- While running in the simulator click on Debug > View Debugging > Capture View Hierarchy and locate your AVPlayer, check the properties on the right panel.
Check the _subview.bounds when you are creating the GMSMapView.
Depending on the time this is done, it might not be setup and you can end-up with a CGRectZero frame.

Google map load on subviews in IOS

I have implement google map in IOS . But the problem is I can not implement google map on my custom view (subview) .
Thanks in advance .
Create a subview and Define the subview class under GMSMapView
- (void)LoadMap {
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_;
// this line add subView
[self.view addSubview : mapView_ ]; }

iOS Google maps sdk - markers are not pointed while using subview instead of main view

Trying to display a simple Google map with a marker at location "position".
If mapview_ is shown in self.view(Default view of controller) instead of gmapsView (subview of self.view) of class GMSMapView then everything is working fine.
I have gone through some of the posts on SO but couldn't solve the issue.
in Interface builder gmapsview class is set to GMSMapView.
Camera Postion setup
CLLocationCoordinate2D position = CLLocationCoordinate2DMake(
37.778376,
-122.409853);
CLLocation *currentLocation = [[CLLocation alloc] initWithLatitude:position.latitude longitude:position.longitude];
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:position.coordinate.latitude
longitude:position.coordinate.longitude
zoom:13];
Map setup
mapView_ = [GMSMapView mapWithFrame:self.gmapsView.frame camera:camera];
mapView_.delegate = self;
self.gmapsView.camera = camera; //gmapsView is a view of class GMSMapView
CGRect rect = self.locationBlockView.frame;
self.gmapsView.delegate = self; //Added to check whether it works
self.gmapsView = mapView_;
Setting up Marker
GMSMarker *marker = [GMSMarker markerWithPosition:position]; //Adding Marker
marker.map = mapView_;
[mapView_ animateToLocation:position.coordinate];
Re-Initializing the map was causing the issue. Once it is removed it solved the issue. But Re-initializing GMSMapView is causing the issue ? Its an absurd thing, but it solved the issue.
CLLocationCoordinate2D position = CLLocationCoordinate2DMake(
12.778376,
-122.409853);
currentLocation = [[CLLocation alloc] initWithLatitude:position.latitude longitude:position.longitude];
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:eventLocation.coordinate.latitude
longitude:eventLocation.coordinate.longitude
zoom:13];
//[self.gmapsView removeFromSuperview];//removing the subview
//self.gmapsView = [GMSMapView mapWithFrame:self.gmapsView.frame camera:camera];
//self.gmapsView.delegate = self;
//self.gmapsView = self.gmapsView; //set map
// [self.view addSubview:self.gmapsView];//Adding back did the magic
self.gmapsView.delegate = self; //set delegate
self.gmapsView.camera = camera; //set camera
GMSMarker *marker = [GMSMarker markerWithPosition:position]; //Adding Marker
marker.map = self.gmapsView;
[self.gmapsView animateToLocation:currentLocation.coordinate];
Add Google Map To Subview
The Solution Steps
1) Change the class of the UIView in the story to GMSMapVIew.
2) Next I created an IBOutlet for the green UIView container and Connected it.
#import <UIKit/UIKit.h>
#import <GoogleMaps/GoogleMaps.h>
#interface CarLocationViewController : UIViewController
//An outlet of type GMSMapView
#property (strong, nonatomic) IBOutlet GMSMapView *mapContainerView;
#end
3) Then in my view did load I did the following
- (void)viewDidLoad {
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.86
longitude:151.20
zoom:14];
GMSMarker *marker = [[GMSMarker alloc] init];
marker.position = CLLocationCoordinate2DMake(-33.86, 151.20);
marker.title = #"Sydney";
marker.snippet = #"Australia";
marker.map = self.mapContainerView;
//set the camera for the map
self.mapContainerView.camera = camera;
self.mapContainerView.myLocationEnabled = YES;
}
I am Following This Link http://www.ryanwright.me/cookbook/ios/obj-c/maps/gmap/subview

GMSMarker points not being shown

I have a viewcontroller in a storyboard with a View in it that loads googlemaps. Markers are however, not showing up!
What have I done wrong?
Here is my code.
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self createBasicGSMView];
}
- (IBAction)AddPointButtonPressed:(id)sender {
// Creates a marker in the center of the map.
GMSMarker *CurrentLocationMarker = [[GMSMarker alloc] init];
CLLocation *CurrentLocationNote = mapView_.myLocation;
CurrentLocationMarker.position = CLLocationCoordinate2DMake(CurrentLocationNote.coordinate.latitude, CurrentLocationNote.coordinate.longitude);
CurrentLocationMarker.title = #"Current Location";
CurrentLocationMarker.snippet = #"This is the place to be";
[CurrentLocationMarker setMap:mapView_];
}
- (void) createBasicGSMView{
// 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:1];
mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];
mapView_.myLocationEnabled = YES;
self.mapViewHolder = 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_;
}
Figured it out. had to add the view as a subview:
[self.view addSubview:mapView_];
Doesnt work otherwise!

Black screen when assigning google maps to subview

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)
}

Resources