5

I am trying to convert the location address to coordinates and open it inside the maps app, but I am getting this error when the function is called. [Client] Geocode error: <private>. That is the only thing printed inside the console.

@IBAction func openinmaps(_ sender: AnyObject) {

    var geocoder: CLGeocoder = CLGeocoder()
    var location = "1 Infinite Loop"

    geocoder.geocodeAddressString(location,completionHandler: {(placemarks: [CLPlacemark]?, error: NSError?) -> Void in
        if (placemarks?.count > 0) {
            var topResult: CLPlacemark = (placemarks?[0])!
            var placemark: MKPlacemark = MKPlacemark(placemark: topResult)

            let regionDistance:CLLocationDistance = 10000
            let coordinates = CLLocationCoordinate2DMake(placemark.coordinate.latitude, placemark.coordinate.latitude)
            let regionSpan = MKCoordinateRegionMakeWithDistance(coordinates, regionDistance, regionDistance)
            let options = [
                MKLaunchOptionsMapCenterKey: NSValue(mkCoordinate: regionSpan.center),
                MKLaunchOptionsMapSpanKey: NSValue(mkCoordinateSpan: regionSpan.span)
            ]

            let mapItem = MKMapItem(placemark: placemark)
            mapItem.openInMaps(launchOptions: options)

            }
        })
    }
manatee
  • 185
  • 1
  • 10

2 Answers2

0

My extension for CLLocationManagerDelegate was randomly crashing because of the same error: [Client] Geocode error: <private> in swift 3.0.

The thing is:

geocoder.reverseGeocodeLocation(startLocation, completionHandler: {

        placemarks, error in


    })

placemarks sometimes was returning nil...

So... I realised that I was playing with my HTTP proxy in order to test some request to the Google API from my device with the Charles Proxy. Removing the Manual HTTP proxy address on my iPhone did the trick and geocoder was working fine again.

I hope it helps.

PD: Nevermind...after 30 seconds or even less, app crashes with the same debug message: [Client] Geocode error:

Michel Goñi
  • 107
  • 1
  • 8
0

I had the same issue, it seems there is a limit when geocoding by address and this is the error for this.

My workaround was to put sleep(1) after each geocode in my loop, find the location latitude and longitude and post them back into my database against each venue I was plotting.

This means it now doesn't need to use the geocoder to plot the annotations on the map as it just uses the lat and long to do so. This will work for fixed sets of data but for stuff on the fly you would need another way. Apparently sleep(2) will enable you to plot continuously through large volumes of data but ends up taking a while for everything to plot.

I've added a default lat and long of 0.0 into my database and upon launching the app it will scan through to find any new venues and will then geocode these and post the lat and long back. I had to do a couple of runs through originally to get ~700 venues lats and longs but I've had no trouble since.