Created
September 16, 2016 21:23
-
-
Save clburlison/872e8cb386ed271afd7c8e73f118c023 to your computer and use it in GitHub Desktop.
Using CoreLocation GeoCoder in PyObjC
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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