2014-11-06 49 views
5

我在Xcode 6.1中顯示谷歌地圖時出現了一些問題我設法讓地圖顯示在UIView的一部分中,但它顯示的是世界地圖而不是特定的座標。谷歌地圖SDK無法在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

有什麼建議?

回答

3

終於找到它了...

刪除:

self.googleMapView = mapView; 

代替:

[self.googleMapView addSubview:mapView]; 
0

我不確定上面的代碼有什麼問題。這對我來說很好。但要將相機移動到某個位置。您也可以在那裏爲相機制作動畫。

var newLocation = CLLocationCoordinate2DMake(latitude, longitude) 
googleMapView.animateToLocation(newLocation) 

希望它適合你。

+0

我基本上是試圖使地圖顯示標記的位置,但它顯示的世界地圖來代替。 – Pangu 2014-11-06 02:31:22

+0

其他人可以幫忙嗎?我搜索了,仍然無法得到這個工作:( – Pangu 2014-11-06 03:43:31

12

你有一個UIView添加到您的故事板......但之後,你有把這個簡單的UIView變成GMSMapView!選擇您剛纔添加的視圖和實用程序工具欄中選擇從左邊數第三個選項卡打開身份檢查,從UIView的更改視圖的類名GMSMapView中,如下面的截圖:

enter image description here

您的插座也不會是這個樣子

@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; 

UPDATE

Here you have an example project(插入你的密鑰)

+0

謝謝!同樣的問題存在和Swift。必須改變UIView – Roman 2015-07-21 13:32:16

+0

的自定義類工作像一個魅力。 – bittu 2016-01-20 10:17:18