I implemented the GMSMapView via the Googla Maps iOS SDK
the example code from Google suggests to declare the view more or less just dropping this method in your code
- (void)loadView {
// 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_;
}
it automagically works, but the mapView happens to cover my navigationItem
it's clear that the maps take its dimension at the initWithFram:CGRectZero
but simply changing the parameter to a custom CGRect
CGRect square = CGRectMake(100, 100, 100, 100);
haven't worked for me, any other suggestion?
i only need to display the map between the Nav Item and the Tab Bar (but the second doesn't happen to be covered)
The problem was that the mapView_ was being set as the whole view
self.view = mapView_;
calculating the correct dimension and adding it as a subview was the correct way to solve it
CGRect f = self.view.frame;
CGRect mapFrame = CGRectMake(f.origin.x, 44, f.size.width, f.size.height);
mapView_ = [GMSMapView mapWithFrame:mapFrame camera:camera];
[self.view addSubview:mapView_];
Make sure your view controller for the map is part of a navigation stack of a UINavigationController. I had no problems pushing a UITabBarController with a map and a list tab onto a view controller embedded in a UINavigationController. This way the navigationbar view belongs only to the UINavigationController and the map controller view shouldn't cover it.
Related
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_;
// I also tried like this - [self.newView Addsubview:mapView_;
}
You can try... what is working for me :)
//header file
...
#property (nonatomic, weak) IBOutlet GMSMapView *mapView;
#property (weak, nonatomic) IBOutlet UIView *subview; //viewForMap
...
implementation file
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:10.8683
longitude:76.2086 zoom:6
bearing:0
viewingAngle:0
];
self.mapView = [GMSMapView mapWithFrame:_subview.bounds camera:camera];
[_subview addSubview:_mapView];
It's hard to say if your problem here is adding the map view or something upstream.
Have you set a breakpoint in -viewDidLoad to ensure that it gets called?
Check the bounds of newView to make sure it's what you expect. Is newView visible? Is it a subview of self.view ?
One trick you can use when trying to ensure your views are where you expect them is to set the background color to something obvious, like red, and then you can see plainly on screen if it's what you expect. If you do this and don't see a red box, then your problem isn't with maps, it's somewhere upstream in the code you haven't shown us.
Good luck.
Create a CGRect with the required frame dimensions and set the MapView frame with method mapWithFrame: and then add the mapview as main subview. Below is the code which explains all. CGRect fr= CGRectMake(0, 44, 768, 960); mapView_ = [GMSMapView mapWithFrame:fr camera:camera]; mapView_.myLocationEnabled = YES; [self.view addSubview:mapView_];
I don't think loadView is called when you are using a xib. I haven't tried using the Google Maps SDK for iOS with a xib, as I create all of my views programmatically.
Maybe you could add your map view in viewDidLoad? So for example:
- (void)viewDidLoad
{
[super viewDidLoad];
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:10.00989
longitude:76.316142
zoom:15];
mapView_ = [GMSMapView
mapWithFrame: CGRectMake(
0, 0,
self.newView.frame.size.width, self.newView.frame.size.height)
camera: camera];
[self.newView addSubview: mapView_];
}
You need to do like this
-(void)loadView {
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:10.00989
longitude:76.316142
zoom:15];
mapView_ = [GMSMapView mapWithFrame:self.newView.bounds camera:camera];
[self.view addSubview:newView];
[self.newView addSubview:mapView_];
}
I want to open a popover on button click event.
Like below image:
But what i m getting is:
The Code i had used for the popover is:
PopOver *PopOver_obj=[[PopOver alloc]initWithNibName:#"PopOver_ipad" bundle:nil ];
UIPopoverController *popoverController = [[UIPopoverController alloc] initWithContentViewController:PopOver_obj];
popoverController.delegate = self;
CGSize maximumLabelSize = CGSizeMake(320.0f,200.0f);
popoverController.popoverContentSize = maximumLabelSize;
CGRect rect = CGRectMake(100,100, 200.0f, 100.0f);
[popoverController presentPopoverFromRect:rect inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
UPDATE
For iOS 5 you can use popoverLayoutMargins property of the popover to set an inset relative to the device's screen edges. See this for more detail.
As far as I can see from your screenshot you have a black colored view and a white one but you are showing the popup in their superview.
You can try using - (void)presentPopoverFromRect:(CGRect)rect inView:(UIView *)view permittedArrowDirections:(UIPopoverArrowDirection)arrowDirections animated:(BOOL)animated method and pass the white view as the view argument of the method and UIPopoverArrowDirectionUp for the arrowDirections argument.
I think that might restrict the popover to go outside the view thus keeping it under your + button.
Let me know if that helps.
I'm facing a problem that is driving me crazy. I read about it around but I didn't find a solution. I'm developing an application that presents modally the view controllers depending on the device orientation. When the device orientation is face up a TabBarController is presented modally. The TabBarController contains two viewControllers one to show a map and the other one (not yet implemented) is for other purposes. When I change the device orientation the application freezes showing the following messages:
MobileAR[8642:707] Using two-stage rotation animation. To use the
smoother single-stage animation, this application must remove
two-stage method implementations.
2011-12-07 21:47:37.566 MobileAR[8642:707] Using two-stage rotation
animation is not supported when rotating more than one view controller
or view controllers not the window delegate The problem that occurs
is that when the loadView: method of the map view controller
There are no problems with the modal presentation of the controller everything works fine as long as the mapviewcontroller loadView: do something else. Here is the code in order to have a better understanding:
If the loadView: is in this way:
- (void)loadView{
UIView *faceUpView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 1024, 718)];
self.view = faceUpView;
[faceUpView release];
MKMapView *mkMap = [[MKMapView alloc] initWithFrame:CGRectMake(0, 0, 1024, 718)];
mkMap.mapType = MKMapTypeStandard;
[self.view addSubview:mkMap];
[mkMap release];
}
doesn't generate any problems, the view, thereby the map is properly visualized within the TabBarController.
Instead if in the loadView: I initialize a view like this:
- (void)loadView{
//Initialize the MapView
MapView *mv = [[MapView alloc] initWithFrame:CGRectMake(0, 0, 1024, 718)];
mv.mapViewController = self;
self.mMapView = mv;
//Release of the local variable
[mv release];
}
it freezes as soon as I put the device "Face Up",even if I leave just the first line: MapView *mv = [[MapView alloc] initWithFrame:CGRectMake(0, 0, 1024, 718)];
Here the implementation of its initializer, MapView.m
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
self.layer.borderWidth = 2; //Set the border of the box
//State that the subviews are confined within its bounds
self.clipsToBounds = YES;
//Initialize the View that contains the map with position and size
// MKMapView *mv = [[MKMapView alloc] initWithFrame:CGRectMake(-106, -106, BOX_SIDE, BOX_SIDE)];
MKMapView *mv = [[MKMapView alloc] initWithFrame:CGRectMake(0, 0, BOX_WIDTH, BOX_HEIGHT)];
//Set the map as standard map (Not satellite nor Hybrid)
mv.mapType = MKMapTypeStandard;
//Retains the map
self.mapView = mv;
//Add the map to the super view
[self addSubview:mv];
//Release the map view previously allocated
[mv release];
}
return self;
}
I didn't ovverride any of the two-stages rotation method neither the one-stage as I read in some answers.
I really appreciate any help!!!!
Thank you
Is it possible to create a view with both an MKMapview and another subview. In particular I have a map view and I have been trying to add a second subview (to the superview, not the MKMapView.) The problem is that while both view can be seen any touches to the UIView that is not the MKMapView pass through to the map. I even tried to move the map so that they do not overlap but the other UIView locates itself relative to the map, not the window.
An additional curiosity is that the code works fine on the simulator, but not on a test device that is running 3.1.3. Could this be a problem with the 3.1.3 version of MKMapView or just a quirk in the simulator?
My code is
combinedView = [[UIView alloc] initWithFrame:self.view.frame];
self.awView = [[AdWhirlView alloc] init];
awView = [AdWhirlView requestAdWhirlViewWithDelegate:self];
self.awView.delegate = self;
[combinedView addSubview:awView];
mapView = [[MKMapView alloc] initWithFrame:CGRectMake(0,50,320,430)];
mapView = (MKMapView*)self.view;
mapView.delegate = self;
//[self.view insertSubview:mapView atIndex:0];
[combinedView addSubview:mapView];
//mapView.showsUserLocation = YES;
// Create a location coordinate object
CLLocationCoordinate2D coordinate;
coordinate.latitude = 40.1;
coordinate.longitude = -76.30575;
// Display map
mapView.region = MKCoordinateRegionMakeWithDistance(coordinate, 40000, 40000);
[combinedView bringSubviewToFront:awView];
Thanks for any advice.
Not too familiar with AdWhirlView, but is it possible you need to set a frame for that as well? CGRectMake(0,0,320,50); or something?
Otherwise, you might want to play with the autoresizeMasks of the two views. I know for certain you can have a MKMapView with sibling views, and they all work fine.
Here's my setup. I have a viewcontroller that I'm creating and adding as a subview. The viewcontroller presents some options that a user can chose from. The viewcontroller is being pushed in response to a "long press" gesture. Within the viewcontroller, I added a child UIView to group some other controls together so I can move them around the screen as a unit and, when they are displayed, center them on the location of the long press. Here is the code that instantiates the view controller, changes its location, and adds it as a subview:
UserOptions *opts = [[UserOptions alloc] initWithNibName:#"UserOptions" bundle:nil];
[opts recenterOptions:location];
[self.view addSubview:opts.view];
That bit of code does create and push the viewcontroller, but the call to recenterOptions doesn't do anything. Here is that method:
- (void) recenterOptions:(CGPoint)location {
CGRect oldFrame = self.optionsView.frame;
CGFloat newX = location.x; // + oldFrame.size.width / 2.0;
CGFloat newY = location.y; // + oldFrame.size.height / 2.0;
CGRect newFrame = CGRectMake(newX, newY, oldFrame.size.width, oldFrame.size.height);
self.optionsView.frame = newFrame;
}
Note that self.optionsView is the child UIView that I added to the viewcontroller's nib.
Does anyone know why I'm unable to change the location of the UIView?
Regards,
Eric
A couple things. First, try adding the view to the view hierarchy before calling -recenterOptions:
UserOptions *opts = [[UserOptions alloc] initWithNibName:#"UserOptions"
bundle:nil];
[self.view addSubview:opts.view];
[opts recenterOptions:location];
Next, just set the center of the view instead of trying to change its frame:
- (void) recenterOptions:(CGPoint)location {
[[self optionsView] setCenter:location];
}
Are you verifying that your optionsView is valid (non-nil)?
I agree with Rob, btw. You need to change your title to match your question.
Views are loaded lazily. Until you call self.view, the view is not loaded and optionsView is nil, hence self.optionsView.frame = newFrame does nothing.