【发布时间】:2016-05-02 05:41:50
【问题描述】:
我正在研究 goole 地图,我在 google 地图上添加以下搜索栏并获取特定搜索地址的坐标。现在我想在选择地点后也将其显示在地图上。请看我的代码。
-(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];
}
我将如何更新地图上的纬度和经度?
【问题讨论】:
-
GMSCameraUpdate *updatedCamera = [GMSCameraUpdate setTarget:坐标缩放:15]; [mapView_animateWithCameraUpdate:updatedCamera];
-
代替坐标传递你的坐标。而 mapView_ 是 GMSMapView 的类型
-
我应该通过 didupdatelocaiton 方法吗?
-
您可以将这两行代码粘贴到 - (void)viewController:(GMSAutocompleteViewController *)viewController didAutocompleteWithPlace:(GMSPlace *)place 方法中,并在坐标位置传递 place.coordinate跨度>
标签: ios objective-c google-maps