我正在使用GoogleMaps SDK,目前我正嘗試將GMSVisibleRegion轉換爲CLRegion。將GMSVisibleRegion轉換爲CLRegion或MKCoordinateRegion
GMSVisibleRegion被定義爲:
typedef struct {
CLLocationCoordinate2D nearLeft;
CLLocationCoordinate2D nearRight;
CLLocationCoordinate2D farLeft;
CLLocationCoordinate2D farRight;
} GMSVisibleRegion;
什麼是這樣做的最快方法是什麼?
不幸的是,很難理解開發人員對「near」和「far」命名的含義。我覺得這個評論也可以用:
/**
* Returns the region (four location coordinates) that is visible according to
* the projection.
*
* The visible region can be non-rectangular. The result is undefined if the
* projection includes points that do not map to anywhere on the map (e.g.,
* camera sees outer space).
*/
- (GMSVisibleRegion)visibleRegion;
非常感謝!
編輯: 好吧,我的第一步是創建一個GMSVisibleRegion的MKCoordinateRegion。
我建議以下代碼將GMSVisibleRegion轉換爲MKCoordinateRegion。任何異議。
+ (MKCoordinateRegion)regionForCenter:(CLLocationCoordinate2D)center andGMSVisibleRegion:(GMSVisibleRegion)visibleRegion
{
CLLocationDegrees latitudeDelta = visibleRegion.farLeft.latitude - visibleRegion.nearLeft.latitude;
CLLocationDegrees longitudeDelta = visibleRegion.farRight.longitude - visibleRegion.farLeft.longitude;
MKCoordinateSpan span = MKCoordinateSpanMake(latitudeDelta, longitudeDelta);
return MKCoordinateRegionMake(center, span);
}
獲得使用MKCoordinateRegion
region
快速擴展是啊,這是有道理的!我在我面前有一個示例代碼來評估你的答案。並會盡快向您報告。希望將來會有更好的文檔。 – 2013-03-05 08:35:38Hi @ xen100,我爲你的問題的後半部分添加了一個關於'MKCoordinateRegion'的更新。 – 2013-03-05 12:59:39
非常感謝!你救了我的一天! :) – 2013-03-05 14:03:27