【发布时间】:2026-01-08 05:00:01
【问题描述】:
使用 MKMapRectMake 创建 MKMapRect 导致编译错误如下:
这是我的代码:
var lat = 37.33072
var lon = -122.029674
var loc = CLLocationCoordinate2D(latitude: lat, longitude: lon)
var point = MKMapPointForCoordinate(loc)
var flyTo = MKMapRectMake(point.x, point.y, 0, 0);
这是编译器的错误:
Undefined symbols for architecture i386:
"_MKMapPointMake", referenced from:
_MKMapRectMake in ViewController.o
"_MKMapSizeMake", referenced from:
_MKMapRectMake in ViewController.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
我的解决方法是使用 origin 和 size 参数创建 MKMapRect。请注意,我已将 MKMapKit 添加到构建阶段中的链接库中
有没有人遇到同样的问题以及如何解决这个问题?
【问题讨论】:
-
确保参数与函数接受的类型相同。它们必须是
Double值。 -
似乎是当前测试版中的一个错误。您可以尝试this answer 中显示的 Objective-C/Swift 桥接解决方法作为临时修复。本质上,在 Objective-C 中调用 MKMapRect 并从 Swift 中调用你的桥接方法。
-
谢谢。这可能是另一种尝试。