【问题标题】:is it possible to get lat long of annotations?是否有可能获得 lat long 的注释?
【发布时间】:2011-03-01 09:26:46
【问题描述】:

我在我的应用程序中使用 iPhone 原生地图。我在数组中有一组 lat、long、title 和 subtitle,并将它们绘制成带有注释的映射。当我单击注释标题和副标题时显示。当我单击注释时,有什么方法可以获取注释的经纬度吗?

【问题讨论】:

    标签: iphone objective-c xcode maps


    【解决方案1】:

    是的。实现MKMapViewDelegate - 协议(reference)的方法- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view。在那里,您可以通过访问annotation - MkAnnotationView 的属性来访问纬度和经度,它符合MkAnnotation - 协议(reference),因此有一个名为coordinate 的属性。

    更新: 以下代码示例在地图上选择注释后打印其纬度/经度:

    - (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view {
       NSLog(@"Latitude: %f", view.annotation.coordinate.latitude);
       NSLog(@"Longitude: %f", view.annotation.coordinate.longitude);
    }
    

    【讨论】:

    • 你能告诉我如何为我的 iPhone 应用程序添加方向吗?我尝试了 google api v3,但未能显示方向,因为它返回到 html。我也尝试过云制作的 SDK,但在免费注册时他们会显示广告。我也试过 route-me,但他们没有给出任何好的解决方案。那么如何在我的 iPhone 应用中显示方向呢?
    【解决方案2】:

    可以实现以下方法

    - (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view {
    
    MapAnnotation *annotation = (MapAnnotation *)view.annotation; //MapAnnotation your class     which conform to MKAnnotation
    
    float lattude = annotation.coordinate.latitude;
    float longtude = annotation.coordinate.longitude;
    
    
    
    }
    

    在符合 MKMapViewDelegate 的类中

    【讨论】:

    • 你能告诉我如何为我的 iPhone 应用程序添加方向吗?我尝试了 google api v3,但未能显示方向,因为它返回到 html。我也尝试过云制作的 SDK,但在免费注册时他们会显示广告。我也试过 route-me,但他们没有给出任何好的解决方案。那么如何在我的 iPhone 应用中显示方向呢?
    • @Zubair NSString *urlString = [NSString stringWithFormat:GOOGLE_MAP_URL,startLatitude, startLongitude, endLatitude, endLongitude]; NSURL *url = [NSURL URLWithString:urlString];和 GoOGLE_MAP_URL = maps.google.com/?saddr=%@,%@&daddr=%@,%@ ,在 Safari 中打开这个 url。
    【解决方案3】:

    斯威夫特 2:0

    添加 MKMapViewDelegate。

        func mapView(mapView: MKMapView, didSelectAnnotationView view: MKAnnotationView){      
    
    let currentAnnotationLattitude = view.annotation?.coordinate.latitude
    
    let currentAnnotationLongitude = view.view.annotation?.coordinate.longitude
            }
    

    注意:它适用于单个地图视图中的多个引脚注释。此委托将提供注释视图的当前纬度和经度。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-02-08
      • 2019-02-12
      • 2020-01-13
      • 2019-07-10
      • 2012-03-25
      • 1970-01-01
      相关资源
      最近更新 更多