首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在MKMap上设置位置

如何在MKMap上设置位置
EN

Stack Overflow用户
提问于 2012-02-10 23:39:02
回答 2查看 489关注 0票数 1

我有4个直角坐标。喜欢

代码语言:javascript
复制
north="55.9504356" south="55.5485293" east="38.1289043" west="37.1044291"

如何在此矩形中设置地图位置?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-02-13 17:53:57

google goecoding给我的视窗<LatLonBox north="55.9504356" south="55.5485293" east="38.1289043" west="37.1044291"/>和俄罗斯地区中心,莫斯科。

代码语言:javascript
复制
   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)];

所以得到了一个中心区域和正常大小的区域。

我的解决方案是,希望它能帮助别人。

票数 1
EN

Stack Overflow用户

发布于 2012-02-11 00:01:25

你应该转换你的坐标。尝试以某种方式获得直方图的中心。下面是我的代码示例:

代码语言:javascript
复制
 CLLocationCoordinate2D coordinate = {[neighborhood.Latitude doubleValue], [neighborhood.Longitude doubleValue]};
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(coordinate, 15000, 15000);
[self.mapView setRegion:region animated:NO];

正如您所看到的,您指出了矩形的中心和距中心的距离,单位为米。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9230333

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档