2014-03-05 67 views
0

我想使用Google Map SDK for IOS在子視圖內實現我目前的位置。我正在嘗試將GMSMapView作爲IBOutlet實現。iOS谷歌地圖SDK - 谷歌地圖不更新到當前位置

我的頭文件中有代碼

#import <UIKit/UIKit.h> 
#import <Google-Maps-iOS-SDK/GoogleMaps/GoogleMaps.h> 

@interface TripLandingViewController : UIViewController 

@property IBOutlet GMSMapView *mapView; 

@end 

我.m文件有代碼

self.view.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"Tile.png"]]; 
    self.mapView.myLocationEnabled = TRUE; 



    NSLog(@"\n\n\n My Location is %f,%f \n\n\n",self.mapView.myLocation.coordinate.latitude,self.mapView.myLocation.coordinate.longitude); 

    GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:self.mapView.myLocation.coordinate.latitude 
                  longitude:self.mapView.myLocation.coordinate.longitude 
                  zoom:10]; 
    self.mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera]; 

不管,我提供用作參數什麼硬編碼值相機中的座標。我得到了錯誤的位置(這裏是英國),這根本沒有更新。

而是當我試圖

self.View = [GMSMapView mapWithFrame:CGRectZero camera:camera]; 

我能夠以正確的位置座標加載在主視圖中正確的地圖視圖。

我試過通過stackoverflow將Google Map添加到SubView的所有答案。

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

How to set the frame for mapview - in google GMSMap for iOS6

How put Google MapView in UIView?

Google Maps iOS SDK, Getting Current Location of user

但似乎沒有任何工作。由於我是IOS編程新手,請幫助。

回答

2

用途:

GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:0 longitude:0 zoom:15]; 
self.mapView.camera = camera; 

使用,而不是:

self.mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera]; 

我不完全知道爲什麼,但這個方法適用於你GMSMapView是你UIViewController的子視圖。