Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/41.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 带有注释的贴图边界框_Iphone_Objective C_Ios_Google Maps_Geometry - Fatal编程技术网

Iphone 带有注释的贴图边界框

Iphone 带有注释的贴图边界框,iphone,objective-c,ios,google-maps,geometry,Iphone,Objective C,Ios,Google Maps,Geometry,我有一个算法,可以计算包含一组给定坐标的地图边界框的大小和位置。虽然它可以完美地工作,但它产生的边界并不总是容纳我放置在坐标处的图钉,该坐标通常位于边界框的边缘上: …而且,它在大多数情况下都会产生可接受的结果: 我已经仔细考虑了一段时间,但我还没有想到一种方法来修改我的算法,以确保图钉始终在边界框内。下面列出了我的算法,如有任何建议,将不胜感激。:) MKMapPoint*points=malloc([坐标计数]*sizeof(MKMapPoint)); MKMapPoint右上角; Mk

我有一个算法,可以计算包含一组给定坐标的地图边界框的大小和位置。虽然它可以完美地工作,但它产生的边界并不总是容纳我放置在坐标处的图钉,该坐标通常位于边界框的边缘上:

…而且,它在大多数情况下都会产生可接受的结果:

我已经仔细考虑了一段时间,但我还没有想到一种方法来修改我的算法,以确保图钉始终在边界框内。下面列出了我的算法,如有任何建议,将不胜感激。:)

MKMapPoint*points=malloc([坐标计数]*sizeof(MKMapPoint));
MKMapPoint右上角;
Mkmapoint lowerLeftCorner;
对于(int i=0;i<[坐标计数];i++)
{
CLLocation*location=[坐标对象索引:i];
CLLocationCoordinate2D坐标=CLLocationCoordinate2D坐标(herp.coordinate.lation,herp.coordinate.longitude);
MKMapPoint point=MKMapPointForCoordinate(坐标);
点[i]=点;
如果(i==0){
右上角=点;
lowerLeftCorner=点;
}
否则{
如果(point.x>upperRightCorner.x)upperRightCorner.x=point.x;
如果(point.y>upperRightCorner.y)upperRightCorner.y=point.y;
如果(点x
我想可能已经晚了,但这里有一个解决方案,它对我很有效,与你的解决方案非常相似,我最后添加了一个填充

- (MKCoordinateRegion)boundingBoxForAnnotations:(NSArray *)annotations { 

CLLocationCoordinate2D topLeftCoord; 
topLeftCoord.latitude = -90; 
topLeftCoord.longitude = 180; 

CLLocationCoordinate2D bottomRightCoord; 
bottomRightCoord.latitude = 90; 
bottomRightCoord.longitude = -180; 

for (id<MKAnnotation> annotation in annotations) {

    topLeftCoord.longitude = fmin(topLeftCoord.longitude, annotation.coordinate.longitude); 
    topLeftCoord.latitude = fmax(topLeftCoord.latitude, annotation.coordinate.latitude); 
    bottomRightCoord.longitude = fmax(bottomRightCoord.longitude, annotation.coordinate.longitude); 
    bottomRightCoord.latitude = fmin(bottomRightCoord.latitude, annotation.coordinate.latitude); 
}

MKCoordinateRegion region; 
region.center.latitude = topLeftCoord.latitude - (topLeftCoord.latitude - bottomRightCoord.latitude) * 0.5; 
region.center.longitude = topLeftCoord.longitude + (bottomRightCoord.longitude - topLeftCoord.longitude) * 0.5; 
region.span.latitudeDelta = fabs(topLeftCoord.latitude - bottomRightCoord.latitude) * 1.1; 

region.span.longitudeDelta = fabs(bottomRightCoord.longitude - topLeftCoord.longitude) * 1.1; 

return region;
-(MKCoordinateRegion)注释的边界框:(NSArray*)注释{
CLLocationCoordinate2D topLeftCoord;
topLeftCoord.纬度=-90;
topLeftCoord.longitude=180;
CLLocationCoordinate2D底部右坐标;
bottomRightCoord.纬度=90;
bottomRightCoord.经度=-180;
用于(注释中的id注释){
topLeftCoord.longitude=fmin(topLeftCoord.longitude,annotation.coordinate.longitude);
topLeftCoord.latitude=fmax(topLeftCoord.latitude,annotation.coordinate.latitude);
bottomRightCoord.longitude=fmax(bottomRightCoord.longitude,annotation.coordinate.longitude);
bottomRightCoord.latitude=fmin(bottomRightCoord.latitude,annotation.coordinate.latitude);
}
协调区域;
region.center.latitude=topLeftCoord.latitude-(topLeftCoord.latitude-bottomRightCoord.latitude)*0.5;
region.center.longitude=topLeftCoord.longitude+(bottomRightCoord.longitude-topLeftCoord.longitude)*0.5;
region.span.latitudeDelta=fabs(topLeftCoord.latitude-bottomRightCoord.latitude)*1.1;
region.span.longitudeDelta=fabs(底部右坐标经度-顶部左坐标经度)*1.1;
返回区;

}

。。。在顶部加一点填充物?这是最简单的方法:)不是你问题的答案,但使用LatLngBounds的extend方法可以更容易地做到这一点
- (MKCoordinateRegion)boundingBoxForAnnotations:(NSArray *)annotations { 

CLLocationCoordinate2D topLeftCoord; 
topLeftCoord.latitude = -90; 
topLeftCoord.longitude = 180; 

CLLocationCoordinate2D bottomRightCoord; 
bottomRightCoord.latitude = 90; 
bottomRightCoord.longitude = -180; 

for (id<MKAnnotation> annotation in annotations) {

    topLeftCoord.longitude = fmin(topLeftCoord.longitude, annotation.coordinate.longitude); 
    topLeftCoord.latitude = fmax(topLeftCoord.latitude, annotation.coordinate.latitude); 
    bottomRightCoord.longitude = fmax(bottomRightCoord.longitude, annotation.coordinate.longitude); 
    bottomRightCoord.latitude = fmin(bottomRightCoord.latitude, annotation.coordinate.latitude); 
}

MKCoordinateRegion region; 
region.center.latitude = topLeftCoord.latitude - (topLeftCoord.latitude - bottomRightCoord.latitude) * 0.5; 
region.center.longitude = topLeftCoord.longitude + (bottomRightCoord.longitude - topLeftCoord.longitude) * 0.5; 
region.span.latitudeDelta = fabs(topLeftCoord.latitude - bottomRightCoord.latitude) * 1.1; 

region.span.longitudeDelta = fabs(bottomRightCoord.longitude - topLeftCoord.longitude) * 1.1; 

return region;