高德地图缩放级别 两个位置 怎么自动缩放等级

高德地图获取两点之间的距离
//1.将两个经纬度点转成投影点
MAMapPoint point1 =
MAMapPointForCoordinate(CLLocationCoordinate2DMake(39..480972));
MAMapPoint point2 =
MAMapPointForCoordinate(CLLocationCoordinate2DMake(39..480441));
//2.计算距离
CLLocationDistance distance =
MAMetersBetweenMapPoints(point1,point2);
摘自高德API文档:/api/ios-sdk/guide/tool/
已投稿到:
以上网友发言只代表其个人观点,不代表新浪网的观点或立场。Pages: 1/2
主题 : MapView方法-设置地图的缩放等级
级别: 精灵王
可可豆: 11179 CB
威望: 11179 点
在线时间: 1002(时)
发自: Web Page
来源于&&分类
MapView方法-设置地图的缩放等级&&&
显示地图的时候,我们希望能够直接设置地图的缩放等级,Google的地图API都有这个参数,MKMapView居然没有,下面这个方法就是帮你搞定的。说明:具体的代码我也是抄来的,刚好需要,再简单封装了一把对原理有兴趣请参见具体的出处 #import &Foundation/Foundation.h&#import &MapKit/MapKit.h&@interface MKMapView (MapViewUtil)- (void)setCenterCoordinate:(CLLocationCoordinate2D)centerCoordinate&&&&&&&&&&&&&&&&&&zoomLevel:(NSUInteger)zoomLevel&&&&&&&&&&&&&&&&&& animated:(BOOL)@end #import &MapViewUtil.h&#define MERCATOR_OFFSET #define MERCATOR_RADIUS 05395@implementation MKMapView (MapViewUtil)#pragma mark -#pragma mark Map conversion methods- (double)longitudeToPixelSpaceX:(double)longitude{&&&&return round(MERCATOR_OFFSET + MERCATOR_RADIUS * longitude * M_PI / 180.0);}- (double)latitudeToPixelSpaceY:(double)latitude{&&&&return round(MERCATOR_OFFSET - MERCATOR_RADIUS * logf((1 + sinf(latitude * M_PI / 180.0)) / (1 - sinf(latitude * M_PI / 180.0))) / 2.0);}- (double)pixelSpaceXToLongitude:(double)pixelX{&&&&return ((round(pixelX) - MERCATOR_OFFSET) / MERCATOR_RADIUS) * 180.0 / M_PI;}- (double)pixelSpaceYToLatitude:(double)pixelY{&&&&return (M_PI / 2.0 - 2.0 * atan(exp((round(pixelY) - MERCATOR_OFFSET) / MERCATOR_RADIUS))) * 180.0 / M_PI;}#pragma mark -#pragma mark Helper methods- (MKCoordinateSpan)coordinateSpanWithMapView:(MKMapView *)mapView&&&&&&&&&&&&&&&&&&&&&&&&&&&& centerCoordinate:(CLLocationCoordinate2D)centerCoordinate&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& andZoomLevel:(NSUInteger)zoomLevel{&&&&// convert center coordiate to pixel space&&&&double centerPixelX = [self longitudeToPixelSpaceX:centerCoordinate.longitude];&&&&double centerPixelY = [self latitudeToPixelSpaceY:centerCoordinate.latitude];&&&&&&&&// determine the scale value from the zoom level&&&&NSInteger zoomExponent = 20 - zoomL&&&&double zoomScale = pow(2, zoomExponent);&&&&&&&&// scale the map’s size in pixel space&&&&CGSize mapSizeInPixels = mapView.bounds.&&&&double scaledMapWidth = mapSizeInPixels.width * zoomS&&&&double scaledMapHeight = mapSizeInPixels.height * zoomS&&&&&&&&// figure out the position of the top-left pixel&&&&double topLeftPixelX = centerPixelX - (scaledMapWidth / 2);&&&&double topLeftPixelY = centerPixelY - (scaledMapHeight / 2);&&&&&&&&// find delta between left and right longitudes&&&&CLLocationDegrees minLng = [self pixelSpaceXToLongitude:topLeftPixelX];&&&&CLLocationDegrees maxLng = [self pixelSpaceXToLongitude:topLeftPixelX + scaledMapWidth];&&&&CLLocationDegrees longitudeDelta = maxLng - minL&&&&&&&&// find delta between top and bottom latitudes&&&&CLLocationDegrees minLat = [self pixelSpaceYToLatitude:topLeftPixelY];&&&&CLLocationDegrees maxLat = [self pixelSpaceYToLatitude:topLeftPixelY + scaledMapHeight];&&&&CLLocationDegrees latitudeDelta = -1 * (maxLat - minLat);&&&&&&&&// create and return the lat/lng span&&&&MKCoordinateSpan span = MKCoordinateSpanMake(latitudeDelta, longitudeDelta);&&&&}#pragma mark -#pragma mark Public methods- (void)setCenterCoordinate:(CLLocationCoordinate2D)centerCoordinate&&&&&&&&&&&&&&&&&&zoomLevel:(NSUInteger)zoomLevel&&&&&&&&&&&&&&&&&& animated:(BOOL)animated{&&&&// clamp large numbers to 28&&&&zoomLevel = MIN(zoomLevel, 28);&&&&&&&&// use the zoom level to compute the region&&&&MKCoordinateSpan span = [self coordinateSpanWithMapView:self centerCoordinate:centerCoordinate andZoomLevel:zoomLevel];&&&&MKCoordinateRegion region = MKCoordinateRegionMake(centerCoordinate, span);&&&&&&&&// set the region like normal&&&&[self setRegion:region animated:animated];}@end
本帖最近评分记录: 共1条评分记录
新浪微博 /pipipengTwitter: qqn_pipi
发帖: 1720
可可豆: 112144 CB
威望: 112793 点
在线时间: 8495(时)
发自: Web Page
皮皮的论坛头像昂?
CC8年生快 | I'm  Developer------------------------------------------------------------Η αγάπη ποτέ δεν αποτυγχάνει.愛是永不止息。Love never fails.
    --《圣经.新约》哥林多前书第13章
级别: 精灵王
可可豆: 11179 CB
威望: 11179 点
在线时间: 1002(时)
发自: Web Page
LV对我头像有意见吗?设置了个新头像,这个还算有型的了引用 引用第1楼lvyile于 06:42发表的  :皮皮的论坛头像昂? [ 此帖被qqn_pipi在 11:12重新编辑 ]
新浪微博 /pipipengTwitter: qqn_pipi
级别: 新手上路
可可豆: 250 CB
威望: 250 点
在线时间: 30(时)
发自: Web Page
非常感谢啊,找这个好久了!!!
级别: 侠客
可可豆: 1176 CB
威望: 1176 点
在线时间: 468(时)
发自: Web Page
MKMapView+MapViewUtil..h MKMapView+MapViewUtil.m
级别: 精灵王
可可豆: 5004 CB
威望: 5004 点
在线时间: 519(时)
发自: Web Page
级别: 新手上路
可可豆: 370 CB
威望: 370 点
在线时间: 50(时)
发自: Web Page
mark一下下下
级别: 新手上路
UID: 38492
可可豆: 171 CB
威望: 170 点
在线时间: 304(时)
发自: Web Page
大哥,能来一个dome吗
级别: 圣骑士
UID: 65157
可可豆: 3436 CB
威望: 3376 点
在线时间: 111(时)
发自: Web Page
额 比想象中的复杂。。。
级别: 骑士
可可豆: 2254 CB
威望: 2254 点
在线时间: 774(时)
发自: Web Page
好东西啊,非常感谢~~
Pages: 1/2
关注本帖(如果有新回复会站内信通知您)
苹果公司现任CEO是谁?2字 正确答案:库克
发帖、回帖都会得到可观的积分奖励。
按"Ctrl+Enter"直接提交
关注CocoaChina
关注微信 每日推荐
扫一扫 浏览移动版}

我要回帖

更多关于 高德地图手势缩放监听 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信