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_];
Related
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.
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.
In my application I have included google maps API but the problem is, it is occupying the entire screen but I dont want it occupy entire screen as I have other UI controls on the same screen. I have my code pasted below.
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:12.9699 longitude:77.6499 zoom:6];
mapView_ = [GMSMapView mapWithFrame: CGRectMake(0,0, 10, 25) camera: camera];
mapView_.myLocationEnabled = YES;
NSLog(#"User's location: %#", mapView_.myLocation);
UIEdgeInsets mapInsets = UIEdgeInsetsMake(100.0,10.0, 10.0, 300.0);
mapView_.padding = mapInsets;
self.view = mapView_;
GMSMarker *marker = [[GMSMarker alloc] init];
marker.position = CLLocationCoordinate2DMake(12.9699,77.6499);
marker.title = #"BANGALORE";
marker.snippet = #"IndraNagar";
marker.map = mapView_;
self.view = mapView_; instead of this add below code
UIView * MApBaseView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];// add your frame size here
[self.view addSubview:MApBaseView];
[MApBaseView addSubview: mapView_];
Try with this code, it work for me:
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:latitude
longitude:longitude
zoom:14];
mapView = [GMSMapView mapWithFrame:mapViewContent.frame camera:camera];
mapView.myLocationEnabled = YES;
mapView.delegate = self;
[mapViewContent addSubview:mapView];
mapViewContent is your view custom.
You should replace marker.map = mapView_; as [self.view addSubview:mapView_];
See the below code
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:locationManager.location.coordinate.latitude
longitude:locationManager.location.coordinate.longitude
zoom:16];
mapView_ = [GMSMapView mapWithFrame:CGRectMake(0, 44, self.view.bounds.size.width, self.view.bounds.size.height-44) camera:camera];
mapView_.myLocationEnabled = YES;
[self.view addSubview:mapView_];
I have created a GMSMapVIew objects as shown in code. Unfortunately, camera is not set on the right coordinates:
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:latitude
longitude:longitude
zoom:15];
mapView_ = [[GMSMapView alloc] initWithFrame:CGRectMake(505, 280, 427, 200)];
mapView_.camera = camera;
mapView_.myLocationEnabled = YES;
UIViewController *mapController = [[UIViewController alloc] initWithNibName:nil bundle:nil];
mapController.view = mapView_;
[self addChildViewController:mapController];
[self.view addSubview:mapView_];
I have tried additionally to relocate camera with following code, but with no success either:
CLLocationCoordinate2D current = CLLocationCoordinate2DMake(latitude,longitude);
GMSCameraUpdate *currentCam = [GMSCameraUpdate setTarget:current];
[mapView_ animateWithCameraUpdate:currentCam];
Does anybody have an idea, what am I doing wrong, or is this simple a bug in Google Maps for iOS?
Are you using the same
CLLocationCoordinate2D current = CLLocationCoordinate2DMake(latitude,longitude);
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:latitude
longitude:longitude
zoom:15];
latitude and longitude? The obviously it wont work as nothing changes ...
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)
}