我正在尝试通过此类在 Watch 应用程序中显示地图:
import WatchKit
class WKMapController: WKInterfaceController {
@IBOutlet var map: WKInterfaceMap!
let mapSpan=0.0001
override func awakeWithContext(context: AnyObject?) {
super.awakeWithContext(context)
if let location = context as? CLLocation {
NSLog("latitude \(location.coordinate.latitude) longitude \(location.coordinate.longitude)")
let size=MKMapSize(width:mapSpan, height: mapSpan)
let mapRect=MKMapRect(origin: MKMapPoint(x: location.coordinate.latitude-mapSpan/2, y: location.coordinate.longitude-mapSpan/2), size: size)
let regionSpan=MKCoordinateSpan(latitudeDelta: size.width, longitudeDelta: size.height)
let region=MKCoordinateRegionMake(location.coordinate, regionSpan)
map.setRegion(region)
map.setVisibleMapRect(mapRect)
}
}
}
这是对应该没问题的 MapRegion 的描述:
Printing description of region:
▿ MKCoordinateRegion
▿ center : CLLocationCoordinate2D
- latitude : 41.7165946960449
- longitude : 12.3110208511353
▿ span : MKCoordinateSpan
- latitudeDelta : 0.0001
- longitudeDelta : 0.0001
然而,只显示空白地图。如何显示真实地图?