Reputation: 1075
I just have a question and can't seem to find it anywhere.
I"m new to iOS development and trying to use Google Maps inside my application.
I went thru the example they give you here.
#import "DemoViewController.h"
#import <GoogleMaps/GoogleMaps.h>
@implementation DemoViewController {
GMSMapView *mapView_;
}
- (void)loadView {
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:1.285
longitude:103.848
zoom:12];
mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];
self.view = mapView_;
}
@end
But as you can see the they set self.view = mapView_;
and the UIView class doesn't have a view function.
I want the map to be inside a UIView I have that is inside another ViewController
Did I lose you yet? Either ways here is a picture.
So inside of the view (or whitespace) I want the map to load.
Thanks guys for the help.
Upvotes: 5
Views: 8724
Reputation: 31
Please try below code.
@property (strong, nonatomic) IBOutlet GMSMapView *mapView;
-(void)addAllPinsOnMapView
{
arrMapPin=[[NSMutableArray alloc] init];
for(int i = 0; i < arrOfferList.count; i++)
{
GMSCameraPosition *cameraPosition=[GMSCameraPosition cameraWithLatitude:[[[arrOfferList objectAtIndex:i] objectForKey:@"latitude"] floatValue] longitude:[[[arrOfferList objectAtIndex:i] objectForKey:@"longitude"] floatValue] zoom:12];
// mapView = [GMSMapView mapWithFrame:CGRectZero camera:cameraPosition];
_mapView.camera = cameraPosition;
_mapView.myLocationEnabled=YES;
GMSMarker *marker=[[GMSMarker alloc]init];
marker.position=CLLocationCoordinate2DMake([[[arrOfferList objectAtIndex:i] objectForKey:@"latitude"] floatValue], [[[arrOfferList objectAtIndex:i] objectForKey:@"longitude"] floatValue]);
marker.title = [[arrOfferList objectAtIndex:i] objectForKey:@"business"];
marker.map=_mapView;
_mapView.delegate = self;
}
}
- (void)mapView:(GMSMapView *)mapView didTapInfoWindowOfMarker:
(GMSMarker *)marker {
NSPredicate *result;
result=[NSPredicate predicateWithFormat:@"business CONTAINS[c] %@",marker.title];
NSArray * array = [arrOfferList filteredArrayUsingPredicate:result];
OfferDetailsViewController *objOfferDetailsViewController = [[OfferDetailsViewController alloc]init];
objOfferDetailsViewController.dictOfferDetails=[array objectAtIndex:0];
[self.navigationController pushViewController:objOfferDetailsViewController animated:YES];
}
- (IBAction)btnLocateMe:(UIButton *)sender
{
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:[[[AppDelegate initAppDelegate].DictLocation objectForKey:@"Latitude"] floatValue] longitude:[[[AppDelegate initAppDelegate].DictLocation objectForKey:@"Longitude"] floatValue] zoom:14];
[_mapView animateToCameraPosition:camera];
}
Upvotes: 1
Reputation: 1972
I did an exact same thing here.
Simply added a View of type GMSMapView
via interface builder and then set up the properties in controller.
Upvotes: 4
Reputation: 1075
I found a solution that works for me if anyone needs to do something similar.
I just used a container view and then made separate UIViewController
class (that has the google maps sdk code add a map section) and then hooked it up to my main ViewController by using [self.view addSubview:googleMapsView];
googleMapsView being my container view that I connected to the main ViewController.
Upvotes: 4
Reputation: 534885
So you've got a GMSMapView. And you can make one view a subview of another in the interface with addSubview:
. I wouldn't do it in loadView
if I were you, though. viewDidLoad
is the earliest good opportunity.
I think your real problem is that you're way ahead of yourself. You're trying to do this without know how views work, how view controllers work, etc. I recommend you take a deep breath and learn about iOS programming before you jump in with all four feet. Otherwise you don't know what your code (or Google's code) even means.
Upvotes: 6