Skip to content

Instantly share code, notes, and snippets.

@clburlison
Created September 16, 2016 21:23
Show Gist options
  • Select an option

  • Save clburlison/872e8cb386ed271afd7c8e73f118c023 to your computer and use it in GitHub Desktop.

Select an option

Save clburlison/872e8cb386ed271afd7c8e73f118c023 to your computer and use it in GitHub Desktop.
Using CoreLocation GeoCoder in PyObjC
#!/usr/bin/python
from CoreLocation import CLLocation
from CoreLocation import CLGeocoder
from Foundation import NSLog, NSRunLoop, NSDate
location = CLLocation.alloc().initWithLatitude_longitude_(37.331762, -122.030561)
address = "1 Infinite Loop, Cupertino, CA 95014"
def myCompletionHandler(placemarks, error):
if error is not None:
print error
else:
print placemarks
# Convert coordinates to address
geocoder = CLGeocoder.alloc().init()
geocoder.reverseGeocodeLocation_completionHandler_(location, myCompletionHandler)
NSRunLoop.currentRunLoop().runUntilDate_(NSDate.dateWithTimeIntervalSinceNow_(3))
# Convert street address into coordinates
geocoder.geocodeAddressString_completionHandler_(address, myCompletionHandler)
NSRunLoop.currentRunLoop().runUntilDate_(NSDate.dateWithTimeIntervalSinceNow_(3))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment