when I using MKLocalSearch by japanese character
let request = MKLocalSearch.Request()
request.naturalLanguageQuery = "東京涩谷地下鉄駅"
request.region = mapView.region
let search = MKLocalSearch(request: request)
search.start {....}
,it can not return the placemark,
shows Error : The operation couldn’t be completed. (MKErrorDomain error 4.). Failed to parse font key token: hiraginosans-w6 how can I fix this problem,thankyou!
import UIKit
import MapKit
class ViewController: UIViewController, MKMapViewDelegate {
@IBOutlet weak var resultsTableView: UITableView!
var mapView: MKMapView!
var searchResults = [MKMapItem]()
override func viewDidLoad() {
super.viewDidLoad()
mapView = MKMapView(frame: CGRect(x: 0, y: 220, width: view.bounds.width, height: view.bounds.height - (tabBarController?.tabBar.frame.size.height ?? 0)))
mapView.showsScale = true
mapView.showsCompass = true
mapView.showsScale = true
mapView.showsUserLocation = true
mapView.userTrackingMode = .follow
mapView.delegate = self
view.addSubview(mapView)
let selectedCoordinate = CLLocationCoordinate2D(latitude: 35.661777, longitude: 139.704051) // some Coordinate near 東京涩谷地下鉄駅
let selectedLocation = CLLocation(latitude: selectedCoordinate.latitude, longitude: selectedCoordinate.longitude)
let coordinateMKCoordinateRegion = MKCoordinateRegion(center: selectedLocation.coordinate, latitudinalMeters: 50000, longitudinalMeters:50000)
mapView.setCenter( selectedLocation.coordinate, animated: true)
mapView.setRegion(coordinateMKCoordinateRegion, animated: true)
drawCircle(radius: 5000, center: selectedLocation.coordinate)
searchForStation()
}
func drawCircle(radius: CLLocationDistance, center: CLLocationCoordinate2D) {
let circle = MKCircle(center: center, radius: radius)
mapView.addOverlay(circle)
}
func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer {
if let circleOverlay = overlay as? MKCircle {
let circleRenderer = MKCircleRenderer(circle: circleOverlay)
circleRenderer.fillColor = nil
circleRenderer.strokeColor = UIColor.blue
circleRenderer.lineWidth = 2.0
return circleRenderer
}
return MKOverlayRenderer(overlay: overlay)
}
func searchForStation() {
print( "searchForStation" )
let request = MKLocalSearch.Request()
request.naturalLanguageQuery = "東京涩谷地下鉄駅" //
request.region = mapView.region
let search = MKLocalSearch(request: request)
search.start { [weak self] (response, error) in
guard let self = self else { return }
guard let response = response, let mapItem = response.mapItems.first else {
print("Error : \(error?.localizedDescription ?? "Unknown error").")
return
}
for mapItem in response.mapItems {
print( "mapItem.placemark =",mapItem.placemark) // hope to get 東京涩谷地下鉄駅placemark,the value of latitudeand longitude)
}
}
}
}