fix: 推算瓦片类型——GCJ→WGS后更接近蓝点=GCJ-02瓦片,反之=WGS-84

This commit is contained in:
xweiba
2026-08-05 22:44:41 +08:00
parent f9b137b0f7
commit 5dd0ef711d
+19 -3
View File
@@ -260,9 +260,25 @@ struct MapViewRepresentable: UIViewRepresentable {
parent.onViewportChanged(distance)
zoomLabel?.text = MapZoomMath.viewportScaleLabel(distanceMeters: distance)
updatePinPosition(on: mapView)
// =GCJ-02=WGS-84
let c = mapView.centerCoordinate
CoordinateConverter.updateTileType(lat: c.latitude, lon: c.longitude)
//
// WGS-84 GCJ-02 ~596m
let mc = mapView.centerCoordinate
if let bl = mapView.userLocation.location?.coordinate {
let wgs = CoordinateConverter.gcj02ToWgs84(lat: mc.latitude, lon: mc.longitude)
let dGCJ = CoordinateConverter.distance(lat1: wgs.lat, lon1: wgs.lon, lat2: bl.latitude, lon2: bl.longitude)
let dRaw = CoordinateConverter.distance(lat1: mc.latitude, lon1: mc.longitude, lat2: bl.latitude, lon2: bl.longitude)
// GCJWGS = GCJ-02 = WGS-84
let type: CoordinateConverter.CoordType = dGCJ < dRaw ? .gcj02 : .wgs84
if type != CoordinateConverter.currentTileType {
CoordinateConverter.currentTileType = type
RuntimeLogger.info("APP", "坐标转换", "推算瓦片 → \(type.rawValue)", details: [
"dGCJ": String(format: "%.0fm", dGCJ), "dRaw": String(format: "%.0fm", dRaw)
])
}
} else {
//
CoordinateConverter.updateTileType(lat: mc.latitude, lon: mc.longitude)
}
// delegate mapState.realtimeLocation nil
if let ul = mapView.userLocation.location,
CLLocationCoordinate2DIsValid(ul.coordinate), ul.horizontalAccuracy >= 0 {