在我的iPad应用程序中,我使用叠加在地图上绘制了一个矩形。 我有一个边的纬度/长度以及长方形的长度和宽度。
我有一些其他经纬度来自数据库。比较经纬度
现在我怎么能从数据库中得到哪些lat-long在矩形内?
感谢,
在我的iPad应用程序中,我使用叠加在地图上绘制了一个矩形。 我有一个边的纬度/长度以及长方形的长度和宽度。
我有一些其他经纬度来自数据库。比较经纬度
现在我怎么能从数据库中得到哪些lat-long在矩形内?
感谢,
已解决。
首先是转换4个latlons使用此方法指向:
CGPoint point = [mapView convertCoordinate:location toPointToView:overlayView];
,那么你必须申请method of point in poly。
试试这个
请使用下面的代码来获得lat和长触摸点。
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,并得到其他lat和长。
得到所有4拉特和长期后,在数据库上做一个SQL查询,并获得相关的结果。
您可以计算距离,如果距离大于当前的经纬度,那么它在外侧,否则它在圆内。您可以使用以下几行来计算距离。
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];