gpt4 book ai didi

ios - 在 map View 中始终显示 Pin 并计算经纬度,ios 中的地址

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:50:35 24 4
gpt4 key购买 nike

在我的 ios 应用程序中,我想在 map 上放置一个图钉,默认情况下它总是显示标注。在那个标注上,我显示了图钉的纬度和经度。

我想要的是大头针始终保持在 map 的中心。当用户移动 map 大头针时,大头针不会移动,但在移动 map 后其纬度会发生变化。

我还想显示那个经纬度的地址。

有什么方法请指点。

我试过这段代码

[mMapView setUserTrackingMode:MKUserTrackingModeFollow animated:YES];
MyAnnotation* obj = [[MyAnnotation alloc] initWithLocation:mMapView.centerCoordinate withPinType:StartPoint];
[obj setTitle:[NSString stringWithFormat:@"%f, %f",mMapView.centerCoordinate.latitude,mMapView.centerCoordinate.longitude]];
[mMapView selectAnnotation:obj animated:YES];
[mMapView addAnnotation:obj];

在当前位置缩放 map 在 map 中心添加图钉显示纬度

问题 - 当我移动 map.pin 时也会移动,而 lat long 没有改变

最佳答案

在您的 -viewDidLoad 方法中添加以下代码,

[mMapView.userLocation addObserver:self  
forKeyPath:@"location"
options:(NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld)
context:NULL];

现在包括以下方法,

// Listen to change in the userLocation
-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
[object setTitle:[NSString stringWithFormat:@"%f, %f",mMapView.centerCoordinate.latitude,mMapView.centerCoordinate.longitude]];
[mMapView selectAnnotation:object animated:YES];
}

请确保您的注释对象是类对象。

希望这会有所帮助...

关于ios - 在 map View 中始终显示 Pin 并计算经纬度,ios 中的地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11096697/

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