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

}

person user3685566    schedule 11.11.2014    source источник


Ответы (1)


Я не пробовал это, но после некоторых исследований API я думаю, что вы можете добиться того, чего хотите, выполнив следующие действия:

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

Надеюсь это поможет.

person MaxK    schedule 23.01.2015