use*_*299 1 google-maps-sdk-ios
我是一个新的谷歌地图sdk for ios.I在视图上添加了一个地图.当我输入这个mapView时,我想定位自己.所以我写道:
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;
Run Code Online (Sandbox Code Playgroud)
但是我在坐标(33.8683,151.2086)中找到了mapView视图,我只想将mapView移动到wyposition.我也发现谷歌没有回调函数参考
self.iMapView.myLocationEnabled = YES;
谢谢你的回复.
Rob*_*ndl 21
要将相机设置为当前位置的动画/设置,首先必须:
self.googleMapsView.myLocationEnabled = YES;
Run Code Online (Sandbox Code Playgroud)
然后在GMSMapView头文件的文档中,您将找到以下注释:
/**
* 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;
Run Code Online (Sandbox Code Playgroud)
因此,您可以在viewWillAppear方法中设置键值观察器,然后使用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]
}
Run Code Online (Sandbox Code Playgroud)
然后观察物业.
- (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]];
}
}
Run Code Online (Sandbox Code Playgroud)
不要忘记在viewWillDisappear中取消注册观察者.
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
// Implement here if the view has registered KVO
...
[self.googleMapsView removeObserver:self forKeyPath:@"myLocation"];
}
Run Code Online (Sandbox Code Playgroud)
最好的祝福
| 归档时间: |
|
| 查看次数: |
9052 次 |
| 最近记录: |