【问题标题】:Comparing Latitude and Longitude比较纬度和经度
【发布时间】:2011-09-28 06:15:50
【问题描述】:

在我的 iPad 应用程序中,我正在使用叠加层在地图上绘制一个矩形。 我有一个边缘的纬度/长度以及矩形的长度和宽度。
我还有一些来自数据库的其他纬度/经度。

现在我如何从数据库中获取哪个经纬度在矩形内?

谢谢,

【问题讨论】:

    标签: ipad map ios-4.2 latitude-longitude


    【解决方案1】:

    已解决。

    首先使用此方法将四个纬度转换为点:

    CGPoint point = [mapView convertCoordinate:location toPointToView:overlayView];
    

    那么你必须申请method of point in poly

    【讨论】:

      【解决方案2】:

      您可以计算距离,如果距离大于当前的经纬度,则它在外侧,否则在圆内。您可以使用以下几行来计算距离。

      CLLocation *location1 = [[CLLocation alloc] initWithLatitude:lat1 longitude:long1];
      
      CLLocation *location2 = [[CLLocation alloc] initWithLatitude:lat2 longitude:long2];
      
      NSLog(@"Distance i meters: %f", [location1 getDistanceFrom:location2]);
      
      [location1 release];
      
      [location2 release];
      

      【讨论】:

        【解决方案3】:

        试试这个

        请使用以下代码获取接触点的经纬度。

        CGRect r = mapView.bounds;
        
            float longitudePercent = overlay.point.x / r.size.width;
            float latitudePercent = overlay.point.y / r.size.height;
        
            CLLocationCoordinate2D coord = mapView.centerCoordinate;
            MKCoordinateSpan span = mapView.region.span;
        
            float lat = coord.latitude + (span.latitudeDelta/2);
            float lon = coord.longitude - (span.longitudeDelta/2);
        

        只需在 overlay.point.x 和 overlay.point.y 中添加矩形的长度和宽度,然后获取其他纬度和经度。

        在获得所有 4 个 lat 和 long 后,对数据库进行 sql 查询并获得相关结果。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2010-09-07
          • 2013-08-12
          • 2018-10-06
          • 2022-10-18
          • 2021-06-19
          • 2017-11-12
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多