gpt4 book ai didi

ios - 是否可以定位 map View ,使用户的当前位置不在 View 的中心?

转载 作者:可可西里 更新时间:2023-11-01 06:24:38 26 4
gpt4 key购买 nike

我在覆盖整个设备屏幕空间的 View 中绘制 map 。

在此 View 之上是占据屏幕下半部分的另一个 View 。顶 View 是半透明的,因此用户可以看到其下方的覆盖 map 。

我在 map 中显示了用户的当前位置。

map View 会自动定位 map ,使用户的位置在 View 中居中 - 因此它是设备屏幕的中心,但是该中心也被顶 View 覆盖。

但是我希望用户的位置位于 map View 未被顶 View 覆盖的部分的中心。

最佳答案

最简单的解决方案是对坐标应用偏移量以稍微移动 map ,利用 MKMapView 区域的跨度。

CLLocationCoordinate2D newCenter = userCoordinate;
newCenter.latitude -= _mapView.region.span.latitudeDelta * 0.50;
[self.mapView setCenterCoordinate:newCenter animated:YES];

0.50 的值只是为了给您举个例子。通过更改它,您可以调整偏移量。

您还可以获取当前中心位置,将其转​​换为 CGPoint,然后将所需的偏移量(以像素为单位)添加到 CGPoint 并将其转换回 CLLocationCoordinate2D :

UIOffset offset = UIOffsetMake(30.0f, 40.0f);
offset.horizontal
offset.vertical

CGPoint point = [_mapView convertCoordinate:userCoordinate
toPointToView:_mapView];
point.x += offset.horizontal;
point.y += offset.vertical;

CLLocationCoordinate2D newCenter = [_mapView convertPoint:point
toCoordinateFromView:_mapView];
[_mapView setCenterCoordinate:newCenter animated:YES];

希望对您有所帮助。

关于ios - 是否可以定位 map View ,使用户的当前位置不在 View 的中心?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22106589/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com