获取mapView gooleMap(GMS MapView)ios的一半中心的经度和纬度

时间:2014-07-10 13:22:46

标签: ios google-maps location latitude-longitude

我正在使用GMS MapView(适用于iOS的Google地图)。我有mapView的四个角以及mapView的中心位置(纬度和长度)。但实际上我想在逻辑上将我的mapView分成两部分,即顶部然后我想获得两个部分的中心点(纬度和长度)。

请参阅附图(我想找到RED Dots的位置(lat& long))。

enter image description here

enter image description here

我该怎么做?

如果你回答它,那就太好了。

谢谢。
格里

1 个答案:

答案 0 :(得分:0)

根据您提供的图像,您将屏幕划分为中间。

试试这个:

    CGFloat screenHeight = [UIScreen mainScreen].bounds.size.height;
    CGFloat middleOfScreenX = [UIScreen mainScreen].bounds.size.width/2;
    CGFloat pointYouDivideScreen = [UIScreen mainScreen].bounds.size.height/2; // this is in order to divide the map exactly in the middle, you can change as you wish



    CGPoint partOneCenterPoint = CGPointMake(middleOfScreenX, pointYouDivideScreen/2);
    CLLocationCoordinate2D partOneCenter = [self.map.projection coordinateForPoint:partOneCenterPoint];

    CGPoint partTwoCenterPoint = CGPointMake(middleOfScreenX, screenHeight - (screenHeight - pointYouDivideScreen)/2);
    CLLocationCoordinate2D partTwoCenter = [self.map.projection coordinateForPoint:partTwoCenterPoint];


    GMSMarker *marker1 = [[GMSMarker alloc] init];
    marker1.position = partOneCenter;
    marker1.map = self.mapView;

    GMSMarker *marker2 = [[GMSMarker alloc] init];
    marker2.position = partTwoCenter;
    marker2.map = self.mapView;

将标记放置在每个部分的中心(仅显示中心)

你可以通过以下方式获得每个中心的纬度/经度。

partOneCenter.latitude;
partOneCenter.longitude;

partTwoCenter.latitude;
partTwoCenter.longitude;