我已经设置了一个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_;
}
我还没有尝试过,但在对API做了一些研究之后,我认为你可以通过以下操作来实现你想要的:
GMSProjection *projection = mapView_.projection;
GMSVisibleRegion visibleRegion = [projection visibleRegion];
GMSCoordinateBounds *coordinateBounds = [[GMSCoordinateBounds alloc] initWithRegion:visibleRegion];
CLLocationCoordinate2D northEast = coordinateBounds.northEast;
CLLocationCoordinate2D southWest = coordinateBounds.southWest;
希望这能有所帮助。