【问题标题】:-convertPoint:toCoordinateFromView: method for Google Maps SDK for iOS [closed]-convertPoint:toCoordinateFromView:适用于 iOS 的 Google Maps SDK 的方法 [关闭]
【发布时间】:2013-02-21 16:36:36
【问题描述】:

如何实现 MapKit 方法

[googleMapView convertPoint:nePoint toCoordinateFromView:pinView];

在 Google Maps SDK for iOS 中?

【问题讨论】:

    标签: objective-c google-maps-sdk-ios


    【解决方案1】:

    你可以使用这样的东西:

    GMSMapView* mapView = ...;
    CGPoint point = ...;
    ...
    CLLocationCoordinate2D coordinate = 
        [mapView.projection coordinateForPoint: point];
    

    在这种情况下,point 应该是相对于地图视图的。

    如果您有一个相对于另一个视图的点(例如 pinView 在您的情况下),您需要先将其转换为相对于地图视图的点。您可以通过以下方式做到这一点:

    UIView* pinView = ...;
    CGPoint pinViewPoint = ...;
    ...
    CGPoint mapViewPoint = [pinView convertPoint: pinViewPoint toView: mapView];
    

    所以将它们组合在一起:

    GMSMapView* mapView = ...;
    UIView* pinView = ...;
    CGPoint pinViewPoint = ...;
    ...
    CGPoint mapViewPoint = [pinView convertPoint: pinViewPoint toView: mapView];
    CLLocationCoordinate2D coordinate = 
        [mapView.projection coordinateForPoint: mapViewPoint];
    

    【讨论】:

    • 感谢您的回答!但是最后一个示例中的 pinViewPoing 是什么?
    • @Mecid:这是相对于您要转换的 pinView 的点 - 在您的示例代码中命名为 nePoint
    • 感谢您的帮助。
    • @SaxonDruce 嗨!我完全想做相反的事情。我想将标记的位置转换为屏幕点。我尝试过投影,但有时它会给我带来负值。你对此有什么想法吗?
    • @NimishaPatel 嗨,Nimisha,相反的是:stackoverflow.com/questions/15066567/… 如果这不起作用,您可能想发布一个带有代码示例的单独问题?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-20
    • 1970-01-01
    相关资源
    最近更新 更多