gpt4 book ai didi

ios - Google Maps SDK 无法在 UIView 中正确显示?

转载 作者:可可西里 更新时间:2023-11-01 04:10:47 26 4
gpt4 key购买 nike

我在 Xcode 6.1 中显示谷歌地图时遇到一些问题

我设法让 map 显示在我的 UIView 的一部分中,但它显示的是世界地图而不是特定坐标。

问题是:

enter image description here

.h:

@interface MapViewController : UIViewController

@property (strong, nonatomic) IBOutlet UIView *googleMapView;

- (IBAction)mapToMain:(UIButton *)sender;

@end

.m:

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.

GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude: 32.915134
longitude: -117.140269 zoom: 17];

GMSMapView *mapView = [GMSMapView mapWithFrame:self.googleMapView.bounds
camera:camera];
mapView.myLocationEnabled = YES;

self.googleMapView = mapView;

GMSMarker *marker = [ [GMSMarker alloc] init];
marker.position = CLLocationCoordinate2DMake(32.915134, -117.140269);
marker.title = @"Tet Festival 2015";
marker.snippet = @"VAYA Tet";
marker.map = mapView;
}

我在这里看到了一些建议,但没有用:

Cannot put a google maps GMSMapView in a subview of main main view?

Using the Google Maps SDK in views other than the main view

有什么建议吗?

最佳答案

您必须将一个 UIView 添加到您的 Storyboard 中……但之后您必须将这个简单的 UIView 变成一个 GMSMapView!选择刚刚添加的 View ,然后通过选择实用程序工具栏左侧的第三个选项卡打开身份检查器,将 View 的类名从 UIView 更改为 GMSMapView,如下面的屏幕截图所示:

enter image description here

你的Outlet不会是这样的

@property (strong, nonatomic) IBOutlet UIView *googleMapView;

会变成这样

@property (strong, nonatomic) IBOutlet GMSMapView *mapView;

你的 ViewDidLoad 可以是这样的:

 GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude: 32.915134
longitude: -117.140269 zoom: 17];

[self.mapView animateToCameraPosition:camera];

GMSMarker *marker = [ [GMSMarker alloc] init];
marker.position = CLLocationCoordinate2DMake(32.915134, -117.140269);
marker.title = @"Tet Festival 2015";
marker.snippet = @"VAYA Tet";
marker.map = self.mapView;

更新

Here you have an example project (插入您的 key )

关于ios - Google Maps SDK 无法在 UIView 中正确显示?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26770522/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com