在iOS地图中搜索附近

时间:2013-06-05 01:27:25

标签: iphone ios mapkit google-maps-sdk-ios apple-maps

我正在尝试使用MapKit构建一个简单的应用程序,该应用程序将在应用程序启动时自动搜索特定位置,并在地图上的位置放置引脚。我看到了各种加载位置的方式(lat / lon等),但没有任何东西可以让我搜索特定的商家名称,餐馆名称等。

我期待与Apple Maps合作。但是,如果谷歌地图是一个比它更好的解决方案。

任何帮助将不胜感激。感谢

3 个答案:

答案 0 :(得分:6)

iOS> = 6.1提供MKLocalSearchMKLocalSearchRequest来搜索感兴趣的自然语言点。样品

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
}];

答案 1 :(得分: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];
        }
}];

}

答案 2 :(得分:0)

进行以下步骤以显示最近的地方。

使用Google API查找最近的地点Google Places API

Google API提供了LAt和Long以及地址信息。

然后将LAt和Long值存储到数组然后使用此lat和long值,您可以在Apple地图(iOS 6+)和Google Map(iOS 5)中显示注释。