关于我自己的定位

关于我自己的定位

本文介绍了关于我自己的定位,一些问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是ios的google map sdk的新手.我在视图上添加了地图.当我输入此mapView时,我想定位自己.所以我写道:

I am a new to google map sdk for ios.I have added a map on a view.When I enter this mapView,I want to positioning myself.So I wrote :

GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.8683
                                                        longitude:151.2086
                                                             zoom:6];
_iMapView = [GMSMapView mapWithFrame:CGRectMake(0, 0, 320, 480) camera:camera];
self.iMapView.myLocationEnabled = YES;
self.iMapView.delegate=self;

GMSMarkerOptions *annotation = [[GMSMarkerOptions alloc] init];
annotation.position = CLLocationCoordinate2DMake(-33.8683, 151.2086);
annotation.title = @"Sydney";
annotation.snippet = @"Australia";
//annotation.infoWindowAnchor=CGPointMake(0.5, 0.5);
[self.iMapView addMarkerWithOptions:annotation];

//[self.view  addSubview:self.iMapView];
self.view=self.iMapView;

但是我在坐标(33.8683,151.2086)中找到了mapView视图,我只想将mapView移动到wyposition.我还发现Google没有对
的回调函数引用 self.iMapView.myLocationEnabled = YES;

but I find the mapView view in the coordinate(33.8683,151.2086),I just want to move the mapView to the wyposition. I also find google have no callback function reference to
self.iMapView.myLocationEnabled = YES;

感谢您的回复.

推荐答案

要将摄像机动画化/设置为当前位置,您首先必须:

To animate/set the camera to your current position you first have to:

self.googleMapsView.myLocationEnabled = YES;

然后在GMSMapView头文件的文档中,您将找到以下注释:

Then in the documentation of the GMSMapView header file you will find the following comment:

/**
* If My Location is enabled, reveals where the user location dot is being
* drawn. If it is disabled, or it is enabled but no location data is available,
* this will be nil.  This property is observable using KVO.
*/
@property (nonatomic, strong, readonly) CLLocation *myLocation;

因此,您可以在viewWillAppear方法中设置键值观察器,然后使用GoogleMaps SDK的位置管理器获取位置更新.

So you can setup a key value observer in your viewWillAppear Method and then you get your location update with the Location Manager of the GoogleMaps SDK.

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];

    // Implement here to check if already KVO is implemented.
    ...
    [self.googleMapsView addObserver:self forKeyPath:@"myLocation" options:NSKeyValueObservingNew context: nil]
}

然后观察该属性.

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
    if ([keyPath isEqualToString:@"myLocation"] && [object isKindOfClass:[GMSMapView class]])
    {
        [self.googleMapsView animateToCameraPosition:[GMSCameraPosition cameraWithLatitude:self.googleMapsView.myLocation.coordinate.latitude
                                                                                 longitude:self.googleMapsView.myLocation.coordinate.longitude
                                                                                      zoom:self.googleMapsView.projection.zoom]];
    }
}

不要忘记在viewWillDisappear中注销观察者的注册.

Do not forget to deregister your observer in the viewWillDisappear.

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    // Implement here if the view has registered KVO
    ...
    [self.googleMapsView removeObserver:self forKeyPath:@"myLocation"];
}

最诚挚的问候

这篇关于关于我自己的定位,一些问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 09:51