我有4个直角坐标。喜欢
north="55.9504356" south="55.5485293" east="38.1289043" west="37.1044291"如何在此矩形中设置地图位置?
发布于 2012-02-13 17:53:57
google goecoding给我的视窗<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)];所以得到了一个中心区域和正常大小的区域。
我的解决方案是,希望它能帮助别人。
发布于 2012-02-11 00:01:25
你应该转换你的坐标。尝试以某种方式获得直方图的中心。下面是我的代码示例:
CLLocationCoordinate2D coordinate = {[neighborhood.Latitude doubleValue], [neighborhood.Longitude doubleValue]};
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(coordinate, 15000, 15000);
[self.mapView setRegion:region animated:NO];正如您所看到的,您指出了矩形的中心和距中心的距离,单位为米。
https://stackoverflow.com/questions/9230333
复制相似问题