sandeep tomar sandeep tomar - 5 months ago 27
iOS Question

How to show search address on google map.?


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?

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