正如标题所说,无论我给出什么坐标,我都会看到相同的位置。
这是我的代码:
我正在使用 Storyboard ,并且我的 View 中有一个 subview 。 subview 是 GMSMapView 类型,并且正确链接。
。H
@property (strong, nonatomic) IBOutlet GMSMapView *mymap;
.m
@implementation DealViewController
{
GMSMapView *mapView_;
}
@synthesize mymap=_mymap;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
[self.view layoutIfNeeded];
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.8683
longitude:151.2086
zoom:6];
mapView_ = [GMSMapView mapWithFrame:CGRectMake(0, 0, 300, 300) camera:camera];
mapView_.myLocationEnabled = YES;
mapView_.mapType = kGMSTypeSatellite;
mapView_.delegate = self;
self.mymap=mapView_;
}
我也试过这个,但我得到了同样的结果:
mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];
以上有什么问题?
最佳答案
经过数小时对同一问题的残酷研究,我发现 viewDidLoad 方法应该如下所示:
- (void)viewDidLoad
{
[super viewDidLoad];
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:obj.latitude
longitude:obj.longitude
zoom:12];
self.mapView.camera = camera;
}
换句话说,在这种情况下,您不应该为 self.mapView 分配任何值(例如 '[GMSMapView mapWithFrame:CGRectMake(0, 0, 300, 300) camera:camera];'),只需设置它的属性 'camera' 值。
这对我有用。我希望这也可以为其他人节省时间。
关于ios - GMSMapView 总是显示相同的位置 iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17427670/