0
votes

I am working on goole map and i add the following for search bar on google map and get the coordinates of particular search address. Now i want to show it on map also after selection on place. Please look at my code.

-(void) searchBarTextDidBeginEditing:(UISearchBar *)searchBar {

GMSAutocompleteViewController *acController = [[GMSAutocompleteViewController alloc] init];
acController.delegate = self;
[self presentViewController:acController animated:YES completion:nil];

}

- (void)viewController:(GMSAutocompleteViewController *)viewController
didAutocompleteWithPlace:(GMSPlace *)place {
// Do something with the selected place.
NSLog(@"Place name %@", place.name);
NSLog(@"Place address %@", place.formattedAddress);
NSLog(@"Place attributions %@", place.attributions.string);
NSLog(@"lat and log%f", place.coordinate.latitude);
NSLog(@"lang %f", place.coordinate.longitude);

CLLocationCoordinate2D *coordinates = CLLocationCoordinate2DMake(place.coordinate.latitude, place.coordinate.longitude);
GMSCameraUpdate *updatedCamera = [GMSCameraUpdate setTarget:coordinates zoom:10];
[_mapView animateWithCameraUpdate:updatedCamera];






[self dismissViewControllerAnimated:YES completion:nil];
  }

 - (void)viewController:(GMSAutocompleteViewController *)viewController
 didFailAutocompleteWithError:(NSError *)error {
// TODO: handle the error.
NSLog(@"error: %ld", (long)[error code]);
[self dismissViewControllerAnimated:YES completion:nil];
 }

   // User canceled the operation.
 - (void)wasCancelled:(GMSAutocompleteViewController *)viewController {
NSLog(@"Autocomplete was cancelled.");
[self dismissViewControllerAnimated:YES completion:nil];
 }

How will i update lat and long on map?

1
GMSCameraUpdate *updatedCamera = [GMSCameraUpdate setTarget:coordinate zoom:15]; [mapView_ animateWithCameraUpdate:updatedCamera];Karthik Mandava
In place of coordinate pass your coordinates. And mapView_ is type of GMSMapViewKarthik Mandava
should i passed is on didupdatelocaiton method?sandeep tomar
you can paste those two lines of code in - (void)viewController:(GMSAutocompleteViewController *)viewController didAutocompleteWithPlace:(GMSPlace *)place method and in the place of coordinate you can pass place.coordinateKarthik Mandava

1 Answers

1
votes
CLLocationCoordinate2D *coordinates = CLLocationCoordinate2DMake(place.coordinate.latitude,place.coordinate.longitude);
GMSCameraUpdate *updatedCamera = [GMSCameraUpdate setTarget:coordinates zoom:10];
 [yourmapViewName animateWithCameraUpdate:cameraUpdate];

Update Answer

 - (void)viewController:(GMSAutocompleteViewController *)viewController
 didAutocompleteWithPlace:(GMSPlace *)place {
// Do something with the selected place.
NSLog(@"Place name %@", place.name);
NSLog(@"Place address %@", place.formattedAddress);
NSLog(@"Place attributions %@", place.attributions.string);
NSLog(@"lat and log%f", place.coordinate.latitude);
NSLog(@"lang %f", place.coordinate.longitude);


 CLLocationCoordinate2D  coordinates = CLLocationCoordinate2DMake(place.coordinate.latitude,place.coordinate.longitude);
GMSCameraUpdate *updatedCamera = [GMSCameraUpdate setTarget:coordinates zoom:10];
 [yourmapViewName animateWithCameraUpdate:cameraUpdate];


 [self dismissViewControllerAnimated:YES completion:nil];
 }