【问题标题】:Get latitude and longitude of center of half of mapView gooleMap (GMS MapView) ios获取mapView gooleMap (GMS MapView) ios一半中心的经纬度
【发布时间】:2014-07-10 13:22:45
【问题描述】:

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

请看附件图片(我想找到红点的位置(纬度和经度)。

我该怎么做?

如果你能回答,真是太好了。

谢谢。
格里

【问题讨论】:

  • 如果你把地图准确地划分在屏幕的中间,那么这两部分的中心不是在屏幕的1/4和屏幕的3/4点吗? (至少中心点的 y 坐标,x 坐标相同)比您可以将屏幕上的点转换为地图上的 lat/lng
  • 尝试使用 GMSProjection 类中的 coordinateForPoint 方法。
  • 非常感谢您的帮助。 我明白了... :-) :-)

标签: ios google-maps location latitude-longitude


【解决方案1】:

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

试试这个:

    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;

【讨论】:

  • 非常感谢您对整个代码的帮助... 我明白了。 :-) :-)
猜你喜欢
  • 1970-01-01
  • 2013-01-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-07-16
相关资源
最近更新 更多