19.3 C
London
Monday, September 2, 2024

ios – CLGeocoder().geocodeAddressString kCLErrorDomain error 8 however identical zipcode working in mapkit searchbar


some zipcodes not working in geocodeAddressString however in searchbar of mapkit. any purpose? have seen identical zipcode working in meals supply apps like Uber eats. Any options please.

import UIKit
import CoreLocation

CLGeocoder().geocodeAddressString("523001") { (placemarks, error) in
    if let error = error {
        print("Geocoding failed with error: (error.localizedDescription)")
        return
    }
    
    if let placemark = placemarks?.first {
        // Entry location info from the placemark
        let location = placemark.location
        print("Geocoding profitable. Location: (location)")
    } else {
        print("No location discovered for the given deal with")
    }
}

however identical zipcode working in searchbar in mapkit
right here mapkit code

import UIKit
import MapKit
import PlaygroundSupport

class MapSearchViewController: UIViewController, MKMapViewDelegate, UISearchBarDelegate, MKLocalSearchCompleterDelegate {
    var mapView: MKMapView!
    var searchCompleter: MKLocalSearchCompleter!
    var searchResults: [MKLocalSearchCompletion] = []
    
    override func viewDidLoad() {
        tremendous.viewDidLoad()

        mapView = MKMapView(body: CGRect(x: 0, y: 0, width: 400, top: 400))
        mapView.delegate = self

        let searchBar = UISearchBar(body: CGRect(x: 0, y: 0, width: 400, top: 50))
        searchBar.placeholder = "Seek for a location"
        searchBar.delegate = self

        view.addSubview(mapView)
        view.addSubview(searchBar)

        searchCompleter = MKLocalSearchCompleter()
        searchCompleter.delegate = self
    }

    // MARK: - UISearchBarDelegate

    func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) {
        searchCompleter.queryFragment = searchText
    }

    // MARK: - MKLocalSearchCompleterDelegate

    func completerDidUpdateResults(_ completer: MKLocalSearchCompleter) {
        searchResults = completer.outcomes
        updateMapAnnotations()
    }

    // MARK: - Map Annotations
func updateMapAnnotations() {
        mapView.removeAnnotations(mapView.annotations)
        for lead to searchResults {
    

Latest news
Related news

LEAVE A REPLY

Please enter your comment!
Please enter your name here