사용이가
@interface ViewController : UIViewController <CLLocationManagerDelegate> {
GMSMapView *mapView_;
GMSMarker *marker_;
float currentLatitude;
float currentLongitude;
}
@property(nonatomic,retain) CLLocationManager *locationManager;
@property (nonatomic)CLLocationCoordinate2D coordinate;
PLIST에서
하는 .m
- (void)viewDidLoad {
[super viewDidLoad];
_locationManager = [[CLLocationManager alloc] init];
[_locationManager setDelegate:self];
[_locationManager setDistanceFilter:kCLDistanceFilterNone];
[_locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
if (IS_OS_8_OR_LATER) {
if ([_locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
[_locationManager requestWhenInUseAuthorization];
}
}
[_locationManager startUpdatingLocation];
}
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations {
NSLog(@"%@",locations);
CLLocation *currentLoc=[locations objectAtIndex:0];
NSLog(@"CurrentLoc : %@",currentLoc);
_coordinate=currentLoc.coordinate;
currentLatitude = currentLoc.coordinate.latitude;
currentLongitude = currentLoc.coordinate.longitude;
}
-(void)plotMarkerForLatitude:(float)latitude andLongitude:(float)longitude {
// Now create maker on current location
if (marker_ == NULL) {
marker_ = [[GMSMarker alloc] init];
}
CLLocationCoordinate2D target =
CLLocationCoordinate2DMake(latitude, longitude);
marker_.position = target;
marker_.title = @"title";
marker_.appearAnimation = kGMSMarkerAnimationPop;
NSLog(@"%f %f",latitude,longitude);
marker_.icon = [UIImage imageNamed:@"marker"];
marker_.snippet = @"Address";
marker_.map = mapView_;
}
.H
:
<key>NSLocationWhenInUseUsageDescription</key>
<string>Allow access to get your current location</string>
답장을 보내 주셔서 감사합니다. 제가 뭄바이에 앉아 있다고 가정하고 GooglePlacePicker로 이동하면서 뉴욕으로 이동합니다. 뉴욕의 좌표를 얻을까요? – Rains
예이 코드는 작동합니다. –
결과가 있습니까? –