gpt4 book ai didi

ios - 谷歌地图 ios 中心的 Objective C 固定标记

转载 作者:可可西里 更新时间:2023-11-01 04:23:09 25 4
gpt4 key购买 nike

我想将标记固定在 map 的中心,而不考虑位置坐标。如果用户在 map 上移动相机,我希望它一直显示在中心,而标记不会闪烁,并且该标记会显示新位置,我该怎么做?请帮忙。

最佳答案

试试下面的 Objective-C 代码

不要忘记设置委托(delegate)

  mapView.delegate=self;

创建ImageView并将其添加到 map 的中心

UIImageView *pin =[[UIImageView alloc]init];
pin.frame=CGRectMake(0, 0, 20, 20 );
pin.center = mapView.center;
pin.image = [UIImage imageNamed:@"location.png"];
[self.view addSubview:pin];
[self.view bringSubviewToFront:pin];

然后使用Google Map的Delegate方法

//When You Will Scroll Map Then This Method Will Be Called
- (void)mapView:(GMSMapView *)MapView didChangeCameraPosition:(GMSCameraPosition *)position {

// Get Latitude And Longitude Of Your Pin(ImageView)
CLLocationCoordinate2D newCoords = CLLocationCoordinate2DMake( position.target.latitude , position.target.longitude);

NSLog(@"Latitude-%f\Longitude-%f\n",newCoords.latitude, newCoords.longitude);


[[GMSGeocoder geocoder] reverseGeocodeCoordinate:CLLocationCoordinate2DMake(newCoords.latitude, newCoords.longitude) completionHandler:^(GMSReverseGeocodeResponse* response, NSError* error) {

//Get Place Details
NSLog(@"%@",[[response results]objectAtIndex:0].lines);

}];
return;
}

关于ios - 谷歌地图 ios 中心的 Objective C 固定标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43222718/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com