如何在ios中使用谷歌地图实现位置搜索?
我正在构建一个iOS应用程序。我正在使用故事板来构建屏幕,我已经在我的项目中集成了谷歌地图 我想在地图上找到点击的位置,并想在Airbnb应用程序中的标签中显示该位置。我无法做到这一点,有人能帮忙吗 这是我的密码:如何在ios中使用谷歌地图实现位置搜索?,ios,objective-c,google-maps,Ios,Objective C,Google Maps,我正在构建一个iOS应用程序。我正在使用故事板来构建屏幕,我已经在我的项目中集成了谷歌地图 我想在地图上找到点击的位置,并想在Airbnb应用程序中的标签中显示该位置。我无法做到这一点,有人能帮忙吗 这是我的密码: - (void)viewDidLoad { [super viewDidLoad]; GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.86
- (void)viewDidLoad {
[super viewDidLoad];
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.86
longitude:151.20
zoom:6];
mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];
mapView_.myLocationEnabled = YES;
self.view = mapView_;
GMSMarker *marker = [[GMSMarker alloc] init];
marker.position = CLLocationCoordinate2DMake(-33.86, 151.20);
marker.title = @"Sydney";
marker.snippet = @"Australia";
marker.map = mapView_;
}
谢谢你的帮助 您必须使用
GMSMapViewDelegate
协议。确切地说,方法mapView:didTapAtCoordinate:
将执行您所需的操作,并检测地图上的点击并提供点击的坐标
要使用该方法,请在视图中添加以下行:
mapView_.delegate = self;
然后在同一类中实现该方法:
- (void)mapView:(GMSMapView *)mapView didTapAtCoordinate:(CLLocationCoordinate2D)coordinate{
// coordinate contains your coordinate :)
NSLog(@"did tap at coordinate: (%f, %f)", coordinate.latitude, coordinate.longitude);
}
更新:要添加标记,可以执行以下操作:
- (void)mapView:(GMSMapView *)mapView didTapAtCoordinate:(CLLocationCoordinate2D)coordinate{
// coordinate contains your coordinate :)
NSLog(@"did tap at coordinate: (%f, %f)", coordinate.latitude, coordinate.longitude);
// Create the marker and add it to the map
CLLocationCoordinate2D position = CLLocationCoordinate2DMake(coordinate.latitude, coordinate.longitude);
GMSMarker *marker = [GMSMarker markerWithPosition:position];
marker.appearAnimation = kGMSMarkerAnimationPop;
marker.map = mapView_;
// Zoom into the current location
GMSCameraPosition *cameraPosition = [GMSCameraPosition cameraWithTarget:position zoom:15.0];
[mapView_ animateToCameraPosition:cameraPosition];
}
你明白我的回答吗?还有什么不清楚的吗?谢谢@nburk我得到了纬度和经度,但是我如何显示区域名称。你必须在地图上添加一个标记,并设置该标记的标题。你到底有什么问题?获取区域名称或在地图上显示带有标记的内容?我用代码更新了答案,添加了标记,并放大了点击的位置。我已经应用了您的代码并点击了标记,但没有获取区域名称,我只是更改了这行CLLocationCoordinate2D position=CLLocationCoordinate2D MAKE(坐标.纬度,坐标.经度);当地图在选项卡上缩放时,没有显示任何内容,只显示灰色地图1。很抱歉,出现了一个小错误,该行确实必须是CLLocationCoordinate2D position=CLLocationCoordinate2DMake(坐标.纬度,坐标.经度);