Appdelegate.m:
@import GooglePlaces;
@import GoogleMaps;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[GMSPlacesClient provideAPIKey:@"123"];
[GMSServices provideAPIKey:@"123"];
return YES;
}
view.h
- (IBAction)searchClicked:(id)sender;
@property (strong, nonatomic) IBOutlet UIBarButtonItem *searchBtn;
view.m
@import GooglePlaces;
@import GooglePlacePicker;
@import GoogleMaps;
@interface ViewController ()
@end
@implementation ViewController{
GMSPlacePicker *_placePicker;
GMSPlacesClient *_placesClient;
double latitudes;
double longitudes;
CLLocationManager *locationManager;
GMSMapView *mapView_;
}
- (void)viewDidLoad {
[super viewDidLoad];
}
- (IBAction)searchClicked:(id)sender {
GMSAutocompleteViewController *acController = [[GMSAutocompleteViewController alloc] init];
acController.delegate = self;
[self presentViewController:acController animated:YES completion:nil];
}
- (void)viewController:(GMSAutocompleteViewController *)viewController
didAutocompleteWithPlace:(GMSPlace *)place {
[self dismissViewControllerAnimated:YES completion:nil];
NSLog(@"Place name %@", place.name);
NSLog(@"Place address %@", place.formattedAddress);
NSLog(@"Place attributions %@", place.attributions.string);
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:place.coordinate.latitude longitude:place.coordinate.longitude zoom:14];
mapView_ = [GMSMapView mapWithFrame:self.view.frame camera:camera];
mapView_.myLocationEnabled = YES;
[mapView_ setMapType:kGMSTypeNormal];
[self.view addSubview:mapView_];
CLLocationCoordinate2D position = CLLocationCoordinate2DMake(place.coordinate.latitude, place.coordinate.longitude);
GMSMarker *london = [GMSMarker markerWithPosition:position];
london.flat = YES;
london.groundAnchor = CGPointMake(0.5, 0.5);
london.map = mapView_;
// //place pick
// CLLocationCoordinate2D center = CLLocationCoordinate2DMake(place.coordinate.latitude ,place.coordinate.longitude);
// CLLocationCoordinate2D northEast = CLLocationCoordinate2DMake(center.latitude + 0.001,
// center.longitude + 0.001);
// CLLocationCoordinate2D southWest = CLLocationCoordinate2DMake(center.latitude - 0.001,
// center.longitude - 0.001);
// GMSCoordinateBounds *viewport = [[GMSCoordinateBounds alloc] initWithCoordinate:northEast
// coordinate:southWest];
// GMSPlacePickerConfig *config = [[GMSPlacePickerConfig alloc] initWithViewport:viewport];
// _placePicker = [[GMSPlacePicker alloc] initWithConfig:config];
//
// [_placePicker pickPlaceWithCallback:^(GMSPlace *place, NSError *error) {
// if (error != nil) {
// NSLog(@"Pick Place error %@", [error localizedDescription]);
// return;
// }
//
//
// }];
//}
}
- (void)viewController:(GMSAutocompleteViewController *)viewController
didFailAutocompleteWithError:(NSError *)error {
[self dismissViewControllerAnimated:YES completion:nil];
// TODO: handle the error.
NSLog(@"Error: %@", [error description]);
}
// User canceled the operation.
- (void)wasCancelled:(GMSAutocompleteViewController *)viewController {
[self dismissViewControllerAnimated:YES completion:nil];
}
// Turn the network activity indicator on and off again.
- (void)didRequestAutocompletePredictions:(GMSAutocompleteViewController *)viewController {
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
}
- (void)didUpdateAutocompletePredictions:(GMSAutocompleteViewController *)viewController {
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
}
@end
story board:
view controller with navigation controller and bar button(search icon)
@import GooglePlaces;
@import GoogleMaps;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[GMSPlacesClient provideAPIKey:@"123"];
[GMSServices provideAPIKey:@"123"];
return YES;
}
view.h
- (IBAction)searchClicked:(id)sender;
@property (strong, nonatomic) IBOutlet UIBarButtonItem *searchBtn;
view.m
@import GooglePlaces;
@import GooglePlacePicker;
@import GoogleMaps;
@interface ViewController ()
@end
@implementation ViewController{
GMSPlacePicker *_placePicker;
GMSPlacesClient *_placesClient;
double latitudes;
double longitudes;
CLLocationManager *locationManager;
GMSMapView *mapView_;
}
- (void)viewDidLoad {
[super viewDidLoad];
}
- (IBAction)searchClicked:(id)sender {
GMSAutocompleteViewController *acController = [[GMSAutocompleteViewController alloc] init];
acController.delegate = self;
[self presentViewController:acController animated:YES completion:nil];
}
- (void)viewController:(GMSAutocompleteViewController *)viewController
didAutocompleteWithPlace:(GMSPlace *)place {
[self dismissViewControllerAnimated:YES completion:nil];
NSLog(@"Place name %@", place.name);
NSLog(@"Place address %@", place.formattedAddress);
NSLog(@"Place attributions %@", place.attributions.string);
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:place.coordinate.latitude longitude:place.coordinate.longitude zoom:14];
mapView_ = [GMSMapView mapWithFrame:self.view.frame camera:camera];
mapView_.myLocationEnabled = YES;
[mapView_ setMapType:kGMSTypeNormal];
[self.view addSubview:mapView_];
CLLocationCoordinate2D position = CLLocationCoordinate2DMake(place.coordinate.latitude, place.coordinate.longitude);
GMSMarker *london = [GMSMarker markerWithPosition:position];
london.flat = YES;
london.groundAnchor = CGPointMake(0.5, 0.5);
london.map = mapView_;
// //place pick
// CLLocationCoordinate2D center = CLLocationCoordinate2DMake(place.coordinate.latitude ,place.coordinate.longitude);
// CLLocationCoordinate2D northEast = CLLocationCoordinate2DMake(center.latitude + 0.001,
// center.longitude + 0.001);
// CLLocationCoordinate2D southWest = CLLocationCoordinate2DMake(center.latitude - 0.001,
// center.longitude - 0.001);
// GMSCoordinateBounds *viewport = [[GMSCoordinateBounds alloc] initWithCoordinate:northEast
// coordinate:southWest];
// GMSPlacePickerConfig *config = [[GMSPlacePickerConfig alloc] initWithViewport:viewport];
// _placePicker = [[GMSPlacePicker alloc] initWithConfig:config];
//
// [_placePicker pickPlaceWithCallback:^(GMSPlace *place, NSError *error) {
// if (error != nil) {
// NSLog(@"Pick Place error %@", [error localizedDescription]);
// return;
// }
//
//
// }];
//}
}
- (void)viewController:(GMSAutocompleteViewController *)viewController
didFailAutocompleteWithError:(NSError *)error {
[self dismissViewControllerAnimated:YES completion:nil];
// TODO: handle the error.
NSLog(@"Error: %@", [error description]);
}
// User canceled the operation.
- (void)wasCancelled:(GMSAutocompleteViewController *)viewController {
[self dismissViewControllerAnimated:YES completion:nil];
}
// Turn the network activity indicator on and off again.
- (void)didRequestAutocompletePredictions:(GMSAutocompleteViewController *)viewController {
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
}
- (void)didUpdateAutocompletePredictions:(GMSAutocompleteViewController *)viewController {
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
}
@end
story board:
view controller with navigation controller and bar button(search icon)
Sign up here with your email
ConversionConversion EmoticonEmoticon