Ios 目标c中的google自动完成
我想使用谷歌自动完成。 我已经实现了UISearchBar和google地图 这是我在viewDidLoad上的谷歌地图代码Ios 目标c中的google自动完成,ios,objective-c,google-maps,autocomplete,Ios,Objective C,Google Maps,Autocomplete,我想使用谷歌自动完成。 我已经实现了UISearchBar和google地图 这是我在viewDidLoad上的谷歌地图代码 _locationManager = [[CLLocationManager alloc] init]; _locationManager.desiredAccuracy = kCLLocationAccuracyBest; _locationManager.delegate = self; [_locationManager startUpdatingLocation]
_locationManager = [[CLLocationManager alloc] init];
_locationManager.desiredAccuracy = kCLLocationAccuracyBest;
_locationManager.delegate = self;
[_locationManager startUpdatingLocation];
GMSCameraPosition *camera = [GMSCameraPosition cameraWithTarget:CLLocationCoordinate2DMake(22.9937266, 72.4987654) zoom:15.0f];
_googleMapView = [GMSMapView mapWithFrame:self.mapView.bounds camera:camera];
_googleMapView.myLocationEnabled = YES;
_googleMapView=_mapView;
_googleMapView.settings.allowScrollGesturesDuringRotateOrZoom = YES;
marker = [[GMSMarker alloc] init];
// marker.position = CLLocationCoordinate2DMake(_locationManager.location.coordinate.latitude, _locationManager.location.coordinate.longitude);
marker.position = CLLocationCoordinate2DMake(22.9937266, 72.4987654);
marker.title = @"Ahmedabad";
marker.icon=[UIImage imageNamed:@"ic_map_car.png"];
marker.snippet = @"India";
marker.map = self.googleMapView;
我想要“当我在搜索栏中键入任何位置时,它将显示在UITableView上,当我选择该位置时,pin将设置为该位置。”
我已经试过了,但没用
给我一些样品演示。
提前感谢。以下是一个非常好的、易于使用的库,用于实现带有自动完成文本字段的谷歌搜索 如何使用:()
- 将“MVPlaceSearchTextField”绑定为中“UITextField”的类
故事板 - 设置其名为“placeSearchDelegate”的委托
- 将API密钥设置为属性“strApiKey”的值创建iOS密钥 从谷歌控制台使用它,了解更多信息
- 使用AppDelegate的选项在DidFinishLaunching中添加以下内容
[GMSServicesprovideAPIKey:@"YOUR API KEY"];
-(void)placeSearch:(MVPlaceSearchTextField*)textField ResponseForSelectedPlace:(GMSPlace*)responseDict . {
CLLocation *userSelectedLocation = [[CLLocation alloc] initWithLatitude:responseDict.coordinate.latitude longitude:responseDict.coordinate.longitude];
marker.position = CLLocationCoordinate2DMake(userSelectedLocation.coordinate.latitude, userSelectedLocation.coordinate.longitude);
marker.map = self.googleMapView; [_googleMapView animateToLocation:userSelectedLocation.coordinate];
[self.googleMapView animateToCameraPosition:[GMSCameraPosition cameraWithTarget:self.googleMapView.camera.target zoom:15.0f]];
}
您只需要在地图上加载数据。它可以是苹果地图或谷歌。它可以节省从字段获取文本、进行web调用、从响应获取数据等所有其他工作。这是代码-(void)locationManager:(CLLocationManager*)manager didUpdateLocations:(NSArray*)locations{CLLocation*currentLocation=[locations lastObject];//NSLog(@“新纬度%f新经度%f”,currentLocation.coordinate.latitude,currentLocation.coordinate.latitude);[\u googleMapView AnimateLocation:currentLocation.coordinate];[self.googleMapView AnimateCameraPosition:[GMSCameraPosition cameraWithTarget:self.googleMapView.camera.target zoom:15.0f]];}但此方法未调用…[\u locationManager startUpdatingLocation]; 将出现“在视图中调用此项”,您需要调用此[\u locationManager RequestWhenUseAuthorization];Too是否要输入区域位置?您是使用MVPlaceSearchTextField,还是从didUpdateLocations:添加pin?