我有两种看法。 1 个加载的 mapbox 查看另一个 map 图像。现在我想通过单击图像中的某个位置来计算 map 位置。
但我没有得到确切的位置。我假设我在 map 上的位置是错误的。
我是这样计算的
-(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;
}
P.N -- 我也尝试过其他方法,但没有用。当你放大到 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。
最佳答案
不要直接访问 map View 的 ScrollView ——它是私有(private) API(尽管是开源的)。看一下这里的方法来代替转换:
https://www.mapbox.com/mapbox-ios-sdk/api/#//api/name/coordinateToPixel :
关于ios - 使用 Mapbox iOS SDK 获取缩放时的 map 大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20524651/