Image of my screen 我想显示一个带有地点选择器的地图。我创建了所需的API,并将其添加到AppDelegate.m中。然后,我在视图控制器中实现了以下代码:
- (void)location
{
GMSPlacePickerConfig *config = [[GMSPlacePickerConfig alloc] initWithViewport:nil];
GMSPlacePickerViewController *placePicker = [[GMSPlacePickerViewController alloc] initWithConfig:config];
placePicker.delegate = self;
[self presentViewController:placePicker animated:YES completion:nil];
}
- (void)placePicker:(GMSPlacePickerViewController *)viewController didPickPlace:(GMSPlace *)place {
[viewController dismissViewControllerAnimated:YES completion:nil];
NSLog(@"Place name %@", place.name);
NSLog(@"Place address %@", place.formattedAddress);
NSLog(@"Place attributions %@", place.attributions.string);
}
- (void)placePickerDidCancel:(GMSPlacePickerViewController *)viewController {
[viewController dismissViewControllerAnimated:YES completion:nil];
NSLog(@"No place selected");
}
我得到了GMSPlacePickerViewController但在我的针脚下没有地图。 有什么想法吗?
答案 0 :(得分:0)
使用视口初始化placePickerConfig时:nil默认为用户的当前位置。执行所有这些操作之前,请确保您具有用户的位置。像这样初始化GMSPlacePickerConfig时,通过提供恒定的地图坐标来测试地图:
let center = CLLocationCoordinate2DMake(-33.86, 151.20)
let northEast = CLLocationCoordinate2DMake(center.latitude + 0.001, center.longitude + 0.001)
let southWest = CLLocationCoordinate2DMake(center.latitude - 0.001, center.longitude - 0.001)
let viewport = GMSCoordinateBounds(coordinate: northEast, coordinate: southWest)
然后使用视口初始化placePickerConfig。 我使用了swift,因为我不了解obj-c,但是您可以轻松地将其转换。如果这是问题所在,则需要先获取用户的坐标