【问题标题】:show Pin always in center on map view and calculate lat long,address in ios始终在地图视图的中心显示 Pin 并在 ios 中计算纬度、地址
【发布时间】:2012-06-19 07:55:10
【问题描述】:

在我的 ios 应用程序中,我想在地图上放置一个默认情况下始终显示标注的图钉。在该标注上我显示的是 lat,long of pin。

我想要的是图钉始终保持在地图的中心。当用户移动地图时,图钉不会移动,但它的纬度在移动地图后会发生变化。

我还想显示该纬度、经度的地址。

请指点有哪些方法。

我已经尝试过这段代码

[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.pin 时,也被移动了,lat long 没有改变

【问题讨论】:

    标签: ios mkmapview


    【解决方案1】:

    在您的 -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];
    }
    

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

    希望这会有所帮助...

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-10-09
      • 2013-02-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-14
      • 1970-01-01
      相关资源
      最近更新 更多