0

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

到目前为止,以下是我的代码:

- (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_;

}
4

1 回答 1

2

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

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

希望这可以帮助。

于 2015-01-23T01:03:19.717 回答