【问题标题】:IOS Google Map SDK - Google Map not updating to current locationIOS Google Map SDK - Google Map 未更新到当前位置
【发布时间】:2014-03-05 05:09:18
【问题描述】:

我正在尝试使用Google Map SDK for IOS 在子视图中实现我的当前位置。我正在尝试将 GMSMapView 实现为 IBOutlet。

我的头文件有代码

 #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 添加到 SubViews 的所有答案。

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 编程的新手。

【问题讨论】:

    标签: ios google-maps-sdk-ios gmsmapview


    【解决方案1】:

    用途:

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

    而不是使用:

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

    我不完全确定为什么,但是当您的 GMSMapView 是您的 UIViewController 的子视图时,此方法有效。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-05
      • 1970-01-01
      相关资源
      最近更新 更多