如何在iphone中获取谷歌地图sdk中的当前位置 [英] how to get current location in google map sdk in iphone
本文介绍了如何在iphone中获取谷歌地图sdk中的当前位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在当前位置设置摄像头,并将缩放级别设置为10.
因此,我已经编写了类似这样的代码,并且对于当前位置,我从这篇文章中获得了提示。
这里是我的代码
mapView _ = [[GMSMapView alloc] initWithFrame:CGRectZero];
CLLocationCoordinate2D currentPosition = mapView_.myLocation.coordinate;
GMSCameraPosition * camera =
[GMSCameraPosition cameraWithTarget:currentPosition zoom:10];
mapView_.camera =相机;
mapView_.delegate = self;
mapView_.mapType = kGMSTypeSatellite;
mapView_.myLocationEnabled = YES;
self.view = mapView_;
mapView_.settings.myLocationButton = YES;
但设备中的坐标为0.00。
请问任何可以帮助解决这个问题吗?
解决方案
试试这个:
@property(nonatomic,retain)IBOutlet GMSMapView * googleMapView;
@property(nonatomic,retain)CLLocationManager * locationManager;
- (void)showCurrentLocation {
_googleMapView.myLocationEnabled = YES;
[self.locationManager startUpdatingLocation]; (CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
GMSCameraPosition * camera = [GMSCameraPosition cameraWithLatitude :newLocation.coordinate.latitude
longitude:newLocation.coordinate.longitude
zoom:17.0];
[_googleMapView animateToCameraPosition:camera];
// ...
}
I want to set camera on current location and zoom level upto 10. So I have written code like this and for current location i get hint from this post.
How to use delegates in Google map API for IOS 6
here is my code
mapView_=[[GMSMapView alloc]initWithFrame:CGRectZero];
CLLocationCoordinate2D currentPosition = mapView_.myLocation.coordinate;
GMSCameraPosition* camera =
[GMSCameraPosition cameraWithTarget: currentPosition zoom: 10];
mapView_.camera = camera;
mapView_.delegate=self;
mapView_.mapType = kGMSTypeSatellite;
mapView_.myLocationEnabled = YES;
self.view = mapView_;
mapView_.settings.myLocationButton = YES;
But coordinate is 0.00 in device.
Please Any Can help to solve out this issue?
解决方案
Try this:
@property (nonatomic, retain) IBOutlet GMSMapView *googleMapView;
@property (nonatomic, retain) CLLocationManager *locationManager;
- (void)showCurrentLocation {
_googleMapView.myLocationEnabled = YES;
[self.locationManager startUpdatingLocation];
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:newLocation.coordinate.latitude
longitude:newLocation.coordinate.longitude
zoom:17.0];
[_googleMapView animateToCameraPosition:camera];
//...
}
这篇关于如何在iphone中获取谷歌地图sdk中的当前位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文