GroundOverlay覆盖整个MapView边界

GroundOverlay覆盖整个MapView边界

我已经设置了一个UIView来使用Google Maps显示地图的特定区域。我现在想在此选定区域的顶部添加图像叠加层,但是我不知道如何为此计算正确的坐标。我已将地图设置为中心坐标,但是“叠加层”需要西北和东南坐标。有人可以帮忙吗?我正在尝试在一些道路上铺设跑道的图像。

下面是到目前为止的代码:

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:14.5809268
                                                       longitude:120.975319
                                                            zoom:16.5
                                                         bearing:90
                                                    viewingAngle:0];

    // Indicating the map frame bounds
    mapView_ = [GMSMapView mapWithFrame:self.mapViewOnScreen.bounds camera: camera];
    mapView_.myLocationEnabled = YES;

    // Add as subview the mapview
    [self.mapViewOnScreen addSubview: mapView_];


    //this is where I need to figure out the coordinates but get stuck...

    CLLocationCoordinate2D southWest = CLLocationCoordinate2DMake(40.712216,-74.22655);
    CLLocationCoordinate2D northEast = CLLocationCoordinate2DMake(40.773941,-74.12544);
    GMSCoordinateBounds *overlayBounds = [[GMSCoordinateBounds alloc] initWithCoordinate:southWest
                                                                          coordinate:northEast];


    //Add track image over the road map to show a race track - roads need to match up

    UIImage *icon = [UIImage imageNamed:@"Track.jpg"];
    GMSGroundOverlay *overlay =
    [GMSGroundOverlay groundOverlayWithBounds:overlayBounds icon:icon];
    overlay.bearing = 0;
    overlay.map = mapView_;

    // Creates a marker in the center of the map.
    GMSMarker *marker = [[GMSMarker alloc] init];
    marker.position = CLLocationCoordinate2DMake(14.5809268, 120.975319);
    marker.title = @"Race Day";
    marker.snippet = @"Manila";
    marker.map = mapView_;

}

最佳答案

我没有尝试过,但是在对API进行了一些研究之后,我认为您可以通过执行以下操作来实现所需的目标:

GMSProjection *projection = mapView_.projection;
GMSVisibleRegion visibleRegion = [projection visibleRegion];
GMSCoordinateBounds *coordinateBounds = [[GMSCoordinateBounds alloc] initWithRegion:visibleRegion];
CLLocationCoordinate2D northEast = coordinateBounds.northEast;
CLLocationCoordinate2D southWest = coordinateBounds.southWest;


希望这可以帮助。

关于ios - GMSMapView GroundOverlay覆盖整个MapView边界,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26867596/

10-09 08:52