Iphone 在特定位置显示谷歌地图

Iphone 在特定位置显示谷歌地图,iphone,google-maps,ios6,Iphone,Google Maps,Ios6,我是IOS开发新手,我正在尝试将谷歌地图添加到示例应用程序中。我正在使用的教程。除了谷歌地图占据了整个屏幕之外,一切正常。显示谷歌地图的代码是 #import <GoogleMaps/GoogleMaps.h> #import "DemoViewController.h" @implementation DemoViewController - (void)viewDidLoad { [super viewDidLoad]; GMSCameraPosition *came

我是IOS开发新手,我正在尝试将谷歌地图添加到示例应用程序中。我正在使用的教程。除了谷歌地图占据了整个屏幕之外,一切正常。显示谷歌地图的代码是

#import <GoogleMaps/GoogleMaps.h>
#import "DemoViewController.h"

@implementation DemoViewController

- (void)viewDidLoad {
  [super viewDidLoad];
  GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.868
                                                          longitude:151.2086
                                                               zoom:6];
  GMSMapView *mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera];

  GMSMarker *marker = [[GMSMarker alloc] init];
  marker.position = camera.target;
  marker.snippet = @"Hello World";
  marker.animated = YES;

  self.view = mapView;
}

@end
ViewController.m

#import "ViewController.h"
#import <GoogleMaps/GoogleMaps.h>

@interface ViewController ()

@end

@implementation ViewController{
    GMSMapView *mapView_;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    CGRect  viewRect = CGRectMake(0, 0, 100, 100);
    _myView = [[UIView alloc] initWithFrame:viewRect];
    [self.view addSubview:_myView];



    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_;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
@end
#导入“ViewController.h”
#进口
@界面视图控制器()
@结束
@实现视图控制器{
GMSMapView*地图视图;
}
-(无效)viewDidLoad
{
[超级视图下载];
//加载视图后,通常从nib执行任何其他设置。
CGRect viewRect=CGRectMake(0,0,100,100);
_myView=[[UIView alloc]initWithFrame:viewRect];
[self.view addSubview:_myView];
GMSCameraPosition*摄像机=[GMSCameraPosition摄像机拍摄时的纬度:-33.86
经度:151.20
缩放:6];
地图视图=[GMSMapView地图WithFrame:CGRectZero相机:相机];
mapView_u2;.myLocationEnabled=是;
self.view=mapView;
//在地图的中心创建一个标记。
GMSMarker*标记=[[GMSMarker alloc]init];
marker.position=CLLocationCoordinate2DMake(-33.86151.20);
marker.title=@“悉尼”;
marker.snippet=@“澳大利亚”;
marker.map=mapView;
}
-(无效)未收到记忆警告
{
[超级记忆警告];
//处置所有可以重新创建的资源。
}
@结束

尝试替换
self.view=mapView在您的
viewDidLoad
方法中使用:

[self.view addSubview:mapView_];
这会将地图视图作为子视图添加到当前视图中

编辑

尝试设置mapView的框架。在[self.view addSubview:mapView_]之前;尝试:

mapView_.frame = CGRectMake(10,10,100,100)];

将10,10100100更改为您想要的mapview框架。

尝试替换
self.view=mapview\ux在您的
viewDidLoad
方法中使用:

[self.view addSubview:mapView_];
这会将地图视图作为子视图添加到当前视图中

编辑

尝试设置mapView的框架。在[self.view addSubview:mapView_]之前;尝试:

mapView_.frame = CGRectMake(10,10,100,100)];

将10,10100100更改为地图视图所需的帧。

是否尝试使用新的子视图并在该子视图中添加
mapview
?@TonyMkenu,我正在使用您的实现,但它正在运行,但未显示地图。您可以添加[self.viewForMap addSubview:_mapView];,但是你没有在主视图中添加viewForMap吗?你有没有尝试使用新的子视图并在该子视图中添加
mapView
?@TonyMkenu,我正在使用你的实现,但它正在运行,但没有显示地图。您可以添加[self.viewForMap addSubview:_mapView];,但是你不在主视图中添加viewForMap吗?你认为我需要调用任何drawRect方法来初始化视图吗???@Noor never。你从来没有叫过drawRect。它会被系统自动调用。您发送消息setNeedsDisplay以强制重画。您认为我需要调用任何drawRect方法来初始化视图吗???@Noor never。你从来没有叫过drawRect。它会被系统自动调用。发送消息setNeedsDisplay以强制重画。