简体   繁体   English

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

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

I have two view. 我有两种看法。 1 loaded mapbox view another map image. 1个已加载的mapbox查看其他地图图像。 Now I want to calculate map position on clicking a position in image. 现在,我想通过单击图像中的位置来计算地图位置。

But I not getting exact position. 但是我没有确切的位置。 I assume map position that I am taking is wrong. 我认为我正在采取的地图位置是错误的。

I am calculating this way 我正在这样计算

-(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 -- I have tried in a alternate way also but not working. PN-我也尝试过其他方法,但没有用。 It's giving perfect when you will zoom upto 4 but after that it's not giving exact position 当您放大到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;

}

Any idea how to do this? 任何想法如何做到这一点?

I am using Mapbox sdk. 我正在使用Mapbox SDK。

https://www.mapbox.com/ https://www.mapbox.com/

Don't go at the map view's scroll view directly -- it's private API (despite being open source). 不要直接进入地图视图的滚动视图,它是私有API(尽管是开源的)。 Take a look at the methods here instead for conversions: 看看这里的转换方法:

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

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

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

and

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

Hope it help you. 希望对您有帮助。

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

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