2013-06-05 3 views
2

MapKit을 사용하여 간단한 응용 프로그램을 만들려고합니다. 앱이 실행되어 위치에서지도에 핀을 놓으면 특정 장소를 자동으로 검색합니다. 위치 (위도/경도 등)를로드하는 데는 여러 가지 방법이 있지만 특정 비즈니스 이름, 레스토랑 이름 등을 검색 할 수있는 방법은 없습니다.iOS에서 가까운 곳에서 검색

Apple Maps에서 작업 할 것으로 예상됩니다. 그러나 Google지도가 더 나은 해결 방법이 될 수 있습니다.

도움을 주시면 감사하겠습니다. 감사합니다

+0

은 무엇을 시도했다의 코드 샘플을 공유하시기 바랍니다, 우리는 당신을 도울 수 있습니다. 감사! – bcr

답변

6

iOS> = 6.1은 자연어 관심 지점을 검색하기 위해 MKLocalSearch, MKLocalSearchRequest을 제공합니다. 샘플

MKLocalSearchRequest *request = [[MKLocalSearchRequest alloc] init]; 
request.region = regionToSearchIn; 
request.naturalLanguageQuery = @"restaurants"; // or business name 
MKLocalSearch *localSearch = [[MKLocalSearch alloc] initWithRequest:request]; 
[localSearch startWithCompletionHandler:^(MKLocalSearchResponse *response, NSError *error) { 
    // do something with the results/error 
}]; 
0

가장 가까운 장소를 표시하려면 다음 단계를 수행하십시오. 구글 API는 가장 가까운 장소 Google Places API

구글 API LAT 롱과 주소 정보를 제공을 찾을 사용

.

그런 다음 배열에 Long 및 Long 값을 저장 한 다음 Apple지도 (iOS 6 이상) 및 Google지도 (iOS 5)에 주석을 표시 할 수있는 위도 및 경도 값을 사용하여 배열에 저장하십시오.

+0

iOS6부터 시작 Google 지역 정보 서비스 약관에 따라 허용되지 않습니다. Google 지역 정보 결과를 표시하려면 Google지도를 사용해야한다고 말합니다. – ilmiacs

+0

최초의 질문은 제 3 자 서비스가 아니라 MapKit에 관한 것입니다. Sanjit의 대답은 정답입니다. – thefaj

1

나는 늦게 알고 있지만 이것이 도움이 되길 바랍니다!

[super viewDidLoad]; 
[self.searchDisplayController setDelegate:self]; 
[self.ibSearchBar setDelegate:self]; 

self.ibMapView.delegate=self; 

// Zoom the map to current location. 
[self.ibMapView setShowsUserLocation:YES]; 
[self.ibMapView setUserInteractionEnabled:YES]; 
[self.ibMapView setUserTrackingMode:MKUserTrackingModeFollow]; 



CLLocationManager *locationManager = [[CLLocationManager alloc] init]; 
locationManager.delegate=self; 

[locationManager startUpdatingLocation]; 
[self.ibMapView setRegion:MKCoordinateRegionMake(locationManager.location.coordinate, MKCoordinateSpanMake(0.2, 0.2))]; 

MKLocalSearchRequest *request = [[MKLocalSearchRequest alloc] init]; 
request.region = self.ibMapView.region; 
request.naturalLanguageQuery = @"restaurant"; 

[UIApplication sharedApplication].networkActivityIndicatorVisible = YES; 
localSearch = [[MKLocalSearch alloc] initWithRequest:request]; 

[localSearch startWithCompletionHandler:^(MKLocalSearchResponse *response, NSError *error){ 

    [UIApplication sharedApplication].networkActivityIndicatorVisible = NO; 

    results = response; 
    if (response.mapItems.count == 0) 
     NSLog(@"No Matches"); 
    else 
     for (MKMapItem *item in response.mapItems) 
     { 
      NSLog(@"name = %@", item.name); 
      NSLog(@"Phone = %@", item.phoneNumber); 

      [_matchingItems addObject:item]; 
      MKPointAnnotation *annotation = 
      [[MKPointAnnotation alloc]init]; 
      annotation.coordinate = item.placemark.coordinate; 
      annotation.title = item.name; 
      [self.ibMapView addAnnotation:annotation]; 
     } 
}]; 

}