0
點的電話號碼我已經創建了一段代碼,將用於與引腳相關的電話號碼搜索我的應用程序在地圖上掉落:搜索並呼籲感興趣
func doCall(_ mapView : MKMapView! , didUpdateUserLocation userLocation : MKUserLocation, placemark:MKPlacemark)
{
let request = MKLocalSearchRequest()
let searchBar = resultSearchController!.searchBar
request.naturalLanguageQuery = searchBar.text
let span = MKCoordinateSpan(latitudeDelta: 0.00000000001, longitudeDelta: 0.0000000001)
let search = MKLocalSearch(request: request)
search.start {MKLocalSearchResponse, error in
for item in (MKLocalSearchResponse?.mapItems)! as [MKMapItem]
{
let optionalString = item.phoneNumber
if let unwrapped = optionalString
{
let center = MKLocalSearchResponse!.mapItems.first!.placemark.coordinate
request.region = MKCoordinateRegion(center: center, span: span)
print(unwrapped)
let cleanUrl = unwrapped.components(separatedBy: CharacterSet.decimalDigits.inverted).joined(separator: "")
let url: URL = URL(string: "tel://" + (cleanUrl))!
UIApplication.shared.openURL(url)
}
}
}
}
然而,這段代碼會返回10個電話號碼,並要求撥打這10個電話號碼中的每一個。我希望代碼返回與該興趣點關聯的單個電話號碼,並要求我給它打電話。
是的!有效!非常感謝。 –
不要忘記接受答案。樂於幫助。 :) –