2014-11-11 2 views
0

iOS 앱을 제작 중입니다. 스토리 보드를 사용하여 화면을 구축하고 있으며 내 프로젝트에 Google지도를 통합했습니다.ios에서 Google지도를 사용하여 위치 검색을 구현하는 방법은 무엇인가요?

지도에서 탭하는 위치를 가져오고 Airbnb 앱과 같은 라벨에 해당 위치를 표시하고 싶습니다. 그럴 수 없습니다. 누군가 도움을 줄 수 있습니다.

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.86 
                  longitude:151.20 
                   zoom:6]; 
    mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera]; 

    mapView_.myLocationEnabled = YES; 
    self.view = mapView_; 
    GMSMarker *marker = [[GMSMarker alloc] init]; 
    marker.position = CLLocationCoordinate2DMake(-33.86, 151.20); 
    marker.title = @"Sydney"; 
    marker.snippet = @"Australia"; 
    marker.map = mapView_; 
} 

도움말이 감사합니다 :

여기 내 코드입니다!

+0

당신은 나의 레스포를 이해합니까? nse? 아직도 불분명 한 무엇인가? – nburk

답변

1

GMSMapViewDelegate 프로토콜을 사용해야합니다. 정확히 mapView:didTapAtCoordinate: 메서드는 필요한 것을 수행하고지도에서 탭을 감지하여 탭 좌표를 제공합니다.

는 방법을 사용에 다음 줄을 추가하여 viewDidLoad :

- (void)mapView:(GMSMapView *)mapView didTapAtCoordinate:(CLLocationCoordinate2D)coordinate{ 
    // coordinate contains your coordinate :) 
    NSLog(@"did tap at coordinate: (%f, %f)", coordinate.latitude, coordinate.longitude); 
} 

업데이트 : 당신이 할 수있는 마커를 추가하려면

mapView_.delegate = self; 

그런 다음 같은 클래스의 메소드를 구현 다음을 수행하십시오.

- (void)mapView:(GMSMapView *)mapView didTapAtCoordinate:(CLLocationCoordinate2D)coordinate{ 
    // coordinate contains your coordinate :) 
    NSLog(@"did tap at coordinate: (%f, %f)", coordinate.latitude, coordinate.longitude); 

    // Create the marker and add it to the map 
    CLLocationCoordinate2D position = CLLocationCoordinate2DMake(coordinate.latitude, coordinate.longitude); 
    GMSMarker *marker = [GMSMarker markerWithPosition:position]; 
    marker.appearAnimation = kGMSMarkerAnimationPop; 
    marker.map = mapView_; 

    // Zoom into the current location 
    GMSCameraPosition *cameraPosition = [GMSCameraPosition cameraWithTarget:position zoom:15.0]; 
    [mapView_ animateToCameraPosition:cameraPosition]; 
} 
+0

감사합니다. @nburk 위도와 경도가 표시되지만 지역 이름을 표시하는 방법은 무엇입니까? – Daljeet

+0

잘 마커를지도에 추가하고 해당 마커의 제목을 설정해야합니다. 당신의 문제는 정확히 무엇입니까? 지역 이름을 얻거나 마커를 사용하여지도에 무언가를 표시 하시겠습니까? – nburk

+0

지도에 마커가 표시된 영역 이름으로 표시됩니다. – Daljeet

관련 문제