Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't forward geocoding with CLGeocoder.geocodeAddressString work in the playground?

I'm attempting to geocode a string into a lat/lon in the swift playground. Here is my code:

import CoreLocation

var geocoder = CLGeocoder()
geocoder.geocodeAddressString("San Francisco, CA", {(placemarks, error)->Void in
    println("here")
})

However, here never gets printed to the console (console output is blank). Why?

like image 220
Zain Avatar asked Feb 12 '23 05:02

Zain


1 Answers

I was having the same issue. While there are some hints to how this is fixed in other posts, I will lay it out here so that others who find this will have something to chew on.

//: Playground - noun: a place where people can play

import UIKit
import CoreLocation
import XCPlayground

var geocoder = CLGeocoder()
var address = "Epcot Center Dr, Orlando FL"


geocoder.geocodeAddressString(address, completionHandler: {(placemarks: [AnyObject]!, error: NSError!) -> Void in

    println(error)

    if let placemark = placemarks?[0] as? CLPlacemark {

        println(placemark.location.coordinate.latitude)
        println(placemark.location.coordinate.longitude)

    }

})


XCPSetExecutionShouldContinueIndefinitely()
like image 84
Christopher Wade Cantley Avatar answered Feb 16 '23 03:02

Christopher Wade Cantley