1
私は、指定された座標のセットを含むマップのバウンディングボックスのサイズと位置を計算するアルゴリズムを持っています。 、注釈付きバウンディングボックス
...そして再び:それは完璧に動作しますが、それが生成する境界は、常に私は、多くの場合、右のバウンディングボックスのエッジ上にある座標に配置プッシュピンに対応していませんそれが許容できる結果にほとんどの時間を生成します。
そのプッシュピンを確実にするために、私はしばらくの間、それを超える混練しましたが、私は私のアルゴリズムを変更する方法を考えることができませんでした常に境界ボックス内にあります。私のアルゴリズムは以下の通りです。どんな提案も大歓迎です。 :)
MKMapPoint *points = malloc([coordinates count] * sizeof(MKMapPoint));
MKMapPoint upperRightCorner;
MKMapPoint lowerLeftCorner;
for(int i = 0; i < [coordinates count]; i++)
{
CLLocation *location = [coordinates objectAtIndex:i];
CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(herp.coordinate.latitude, herp.coordinate.longitude);
MKMapPoint point = MKMapPointForCoordinate(coordinate);
points[i] = point;
if (i == 0) {
upperRightCorner = point;
lowerLeftCorner = point;
}
else {
if (point.x > upperRightCorner.x) upperRightCorner.x = point.x;
if (point.y > upperRightCorner.y) upperRightCorner.y = point.y;
if (point.x < lowerLeftCorner.x) lowerLeftCorner.x = point.x;
if (point.y < lowerLeftCorner.y) lowerLeftCorner.y = point.y;
}
}
MKMapRect boundingBox = MKMapRectMake(lowerLeftCorner.x, lowerLeftCorner.y,
upperRightCorner.x - lowerLeftCorner.x,
upperRightCorner.y - lowerLeftCorner.y);
...トップにパディングを少し追加しますか?それは最も簡単な方法です:) – Ryan
あなたの質問への答えではありませんが、これはLatLngBoundsのextend-methodを使用すると簡単に行うことができます –