将 GMSMapView 坐标转换为 iPhone 屏幕点(x,y)
Convert GMSMapView coordinate to iPhone screen point(x,y)
我试图将标记位置的经纬度转换为 iPhone 屏幕 x 和 y 坐标,但有时它会给我负值。
MapView 已添加到故事板的主视图中。
self.mapView.frame - 等于主视图框
iPhone8加模拟器=(origin=(x=0,y=0),size=(width=414,height=736))
标记位置:(纬度 = 22.811061859130859,经度 = 70.862533569335938)
CGPoint pointInScreen = [self.mapView.projection pointForCoordinate:marker.position];
Returns 值 - (x = -38547.58203125, y = 7061.60107421875)
这不是屏幕点。我的标记在屏幕上可见。
谁能建议我根据标记经纬度位置找出屏幕 x,y 坐标的正确方法?
要检查的东西很少:
marker
应该在地图上可见。
- 交叉检查你的
coordinates
。
[self.mapView.projection pointForCoordinate:marker.position]
正确加载地图后功能将生效。
你必须这样做
- 使用 GMSVisibleRegion 检索视口的边界。
- 创建 GMSCoordinateBounds
- 致电containsCoordinate。如果标记在视口内,它应该 return 为真,否则为假。
我试图将标记位置的经纬度转换为 iPhone 屏幕 x 和 y 坐标,但有时它会给我负值。
MapView 已添加到故事板的主视图中。 self.mapView.frame - 等于主视图框 iPhone8加模拟器=(origin=(x=0,y=0),size=(width=414,height=736))
标记位置:(纬度 = 22.811061859130859,经度 = 70.862533569335938)
CGPoint pointInScreen = [self.mapView.projection pointForCoordinate:marker.position];
Returns 值 - (x = -38547.58203125, y = 7061.60107421875) 这不是屏幕点。我的标记在屏幕上可见。
谁能建议我根据标记经纬度位置找出屏幕 x,y 坐标的正确方法?
要检查的东西很少:
marker
应该在地图上可见。- 交叉检查你的
coordinates
。 [self.mapView.projection pointForCoordinate:marker.position]
正确加载地图后功能将生效。
你必须这样做
- 使用 GMSVisibleRegion 检索视口的边界。
- 创建 GMSCoordinateBounds
- 致电containsCoordinate。如果标记在视口内,它应该 return 为真,否则为假。