我有4個座標的矩形。 像如何在MKMap上設置位置
north="55.9504356" south="55.5485293" east="38.1289043" west="37.1044291"
我怎麼可以設置在這個矩形的地圖位置?
我有4個座標的矩形。 像如何在MKMap上設置位置
north="55.9504356" south="55.5485293" east="38.1289043" west="37.1044291"
我怎麼可以設置在這個矩形的地圖位置?
谷歌goecoding給我viewport <LatLonBox north="55.9504356" south="55.5485293" east="38.1289043" west="37.1044291"/>
和俄羅斯,莫斯科地區的中心。
CLLocationCoordinate2D centerOfRegion = CLLocationCoordinate2DMake([data.coordinatesLongitude doubleValue],[data.coordinatesLatitude doubleValue]); //37.6166667,55.7500000
//N+E S+W for get distance between
double lat1 = [[data.squareArray objectAtIndex:0] doubleValue];
double lng1 = [[data.squareArray objectAtIndex:2] doubleValue];
double lat2 = [[data.squareArray objectAtIndex:1] doubleValue];
double lng2 = [[data.squareArray objectAtIndex:3] doubleValue];
CLLocation *firstLocation = [[[CLLocation alloc] initWithLatitude:lat1 longitude:lng1] autorelease];
CLLocation *secondLocation = [[[CLLocation alloc] initWithLatitude:lat2 longitude:lng2] autorelease];
// and /2 to make a little smaller viewport
CLLocationDistance distance = [secondLocation distanceFromLocation:firstLocation];
[map setRegion:MKCoordinateRegionMakeWithDistance(centerOfRegion, distance/2, distance/2)];
所以一箇中心區域和規範的區域大小。
我的解決方案是這樣的,希望可以幫助別人。
你應該轉換你的座標。試着以某種方式獲得rect的中心。以下是我的代碼示例:
CLLocationCoordinate2D coordinate = {[neighborhood.Latitude doubleValue], [neighborhood.Longitude doubleValue]};
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(coordinate, 15000, 15000);
[self.mapView setRegion:region animated:NO];
正如您所看到的,您指出了矩形中心和距離中心的距離(以米爲單位)。
此方法使矩形和距離的中心,但我需要4座標rect。 Thx,但這個沒有迴應我的情況。 – 2012-02-10 16:11:40
MKCoordinateRegion 定義要顯示地圖哪部分的結構。 typedef struct { CLLocationCoordinate2D center; MKCoordinateSpan跨度; } MKCoordinateRegion; 因此,你可以看到你沒有辦法以其他方式創建這個結構 – Stas 2012-02-10 16:25:46
這很糟糕,無論如何thx :) – 2012-02-10 16:32:52