iOS
[Swift/iOS] Kakao 지도 iOS API 지도 화면 영역 내의 좌표
guswlsdk
2022. 6. 16. 11:33
반응형
지도 화면 영역 내의 좌표를 구하고자 하였으나, 카카오에서 제공하는 Kakao 지도 iOS API 문서에 찾아도 안 나와서 헤더파일을 뒤져가며 찾았다.
[MTMapView.h]
MTMapView 아래 내가 찾던 mapBounds가 있다.
좌하단의 좌표(x1, y1)와 우상단의 좌표(x2, y2)를 구할 수 있다.
다음은 mapBounds를 활용하여 작성한 코드이다.
func initMapPoint(){ // 벡엔드에서 받아와서 마커 표시
if let bounds = self.mtMapView.mapBounds{
let bottomLeftPoint = bounds.bottomLeft.mapPointGeo()
let topRightPoint = bounds.topRight.mapPointGeo()
let items = MapManager.shared.mapList.filter{
bottomLeftPoint.longitude < $0.longitude &&
bottomLeftPoint.latitude < $0.latitude &&
topRightPoint.latitude > $0.latitude &&
topRightPoint.longitude > $0.longitude
}
for item in items{
let poiItem = MTMapPOIItem()
poiItem.markerType = .bluePin
poiItem.mapPoint = MTMapPoint(geoCoord: MTMapPointGeo(latitude: item.latitude, longitude: item.longitude))
self.mtMapView.add(poiItem)
}
}
}
반응형