gho*_*der 1 ios google-maps-sdk-ios gmsmapview
正如标题所说,无论我给出什么坐标,我都会看到相同的位置.
这是我的代码:
我正在使用故事板,我的视图中有一个子视图.子视图的类型为GMSMapView,并且链接正确.
.H
@property (strong, nonatomic) IBOutlet GMSMapView *mymap;
Run Code Online (Sandbox Code Playgroud)
.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_;
}
Run Code Online (Sandbox Code Playgroud)
我也试过这个,但我得到了同样的结果:
mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];
Run Code Online (Sandbox Code Playgroud)
上面有什么问题?
经过几个小时的残酷研究同样的问题,我发现viewDidLoad方法应该是这样的:
- (void)viewDidLoad
{
[super viewDidLoad];
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:obj.latitude
longitude:obj.longitude
zoom:12];
self.mapView.camera = camera;
}
Run Code Online (Sandbox Code Playgroud)
换句话说,在这种情况下,你不应该将任何值(如'[GMSMapView mapWithFrame:CGRectMake(0,0,300,300)camera:camera];')分配给self.mapView,只需设置它的属性'camera'值即可.
这适合我.我希望这也能为其他人节省时间.
如果您使用的是故事板,请确保在故事板UI中将视图类型设置为GMSMapView.
那你需要做的就是:
- (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];
self.mymap.camera = camera;
self.mymap.myLocationEnabled = YES;
self.mymap.mapType = kGMSTypeSatellite;
self.mymap.delegate = self;
}
Run Code Online (Sandbox Code Playgroud)
Google Maps github页面上提供了一个故事板示例.
| 归档时间: |
|
| 查看次数: |
7008 次 |
| 最近记录: |