2016-10-23 3 views
0

Google지도에서 현재 마커 위치 좌표를 선택해야합니다. 지도에서 마커가 움직이는 동안 좌표가 업데이트되어야합니다.Google지도에서 움직이는 마커의 GPS 좌표 가져 오기 iOS

나는 Google지도, GooglePlacesGooglePlacePicker API의를 사용하고 있습니다. GooglePlacePicker API를 사용하여 주변 장소를 얻을 수 있지만 마커가있는 위치의 정확한 좌표를 선택하고 싶습니다.

이미 완료되었습니다 Uber?

답변

0

사용이가

@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> 
+0

답장을 보내 주셔서 감사합니다. 제가 뭄바이에 앉아 있다고 가정하고 GooglePlacePicker로 이동하면서 뉴욕으로 이동합니다. 뉴욕의 좌표를 얻을까요? – Rains

+0

예이 코드는 작동합니다. –

+0

결과가 있습니까? –

0

이것은 아마도 GMSMapViewDelegate 프로토콜을 구현하여 수행 할 수 있습니다. guide to eventsGMSMapViewDelegate에있는 방법 목록을 참조하십시오.

문서에서 언급 한 바와 같이

,

응용 프로그램은 모든 카메라 변화에 대한 내용을 다시로드, 예를 들어, GMSMapView의에 표시되는 마커 또는 기타 콘텐츠의 새로 고침을 트리거하는 대신이 이벤트를 사용할 수 있습니다.

위치 관련 앱과 사이트를 구축하기 위해 Maps iOS SDK와 함께 사용할 수있는 다른 API에 대한 자세한 내용은 Google Maps SDK for iOS을 확인하시기 바랍니다.

관련 문제