繁体   English   中英

使用Mapbox iOS SDK缩放获取地图大小

[英]Get map size on zoom using Mapbox iOS SDK

我有两种看法。 1个已加载的mapbox查看其他地图图像。 现在,我想通过单击图像中的位置来计算地图位置。

但是我没有确切的位置。 我认为我正在采取的地图位置是错误的。

我正在这样计算

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{

       CGPoint location=[[touches anyObject] locatinInView:self];

       CGPoint point;
       point.x=(location.x * self.mapView.mapScrollView.contentSize.width)/self.size.width);
       point.y=(location.y * self.mapView.mapScrollView.contentSize.height)/self.size.height);

       mapView.mapScrollView.contentOffset=point;

}

PN-我也尝试过其他方法,但没有用。 当您放大到4时,它可以提供完美的效果,但之后却无法给出确切的位置

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{

       CGPoint location=[[touches anyObject] locatinInView:self];

       CGPoint point;
       point.x=(location.x * self.mapView.projection.planetBounds.size.width/self.mapView.metersPerPixel)/self.size.width);
       point.y=(location.y * self.mapView.mapScrollView.projection.planetBounds.size.height/self.mapView.metersPerPixel)/self.size.height);

       mapView.mapScrollView.contentOffset=point;

}

任何想法如何做到这一点?

我正在使用Mapbox SDK。

https://www.mapbox.com/

不要直接进入地图视图的滚动视图,它是私有API(尽管是开源的)。 看看这里的转换方法:

https://www.mapbox.com/mapbox-ios-sdk/api/#//api/name/coordinateToPixel

MapBox iOS SDK具有以下委托方法-(void)singleTapOnMap:(RMMapView *)mapView at:(CGPoint)point;

RMMapView具有方法-(CLLocationCoordinate2D)pixelToCoordinate:(CGPoint)pixelCoordinate提示:[mapView pixelToCoordinate:(CGPoint)];

  • (CGPoint)coordinateToPixel:(CLLocationCoordinate2D)coordinate提示:[mapViewordinateToPixel:coordinate];

希望对您有帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM