-
Notifications
You must be signed in to change notification settings - Fork 17
/
geocodeAddressString.py
37 lines (35 loc) · 1 KB
/
geocodeAddressString.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from objc_util import *
import time
def geocodeAddressString(address):
global handler_done,gps
handler_done = None
gps = (None,None)
# check if contact without address
def handler(_cmd,obj1_ptr,_error):
global handler_done,gps
if not _error and obj1_ptr:
obj1 = ObjCInstance(obj1_ptr)
ret = str(obj1)
#print(ret)
t = 'center:<'
i = ret.find(t)
if i >= 0:
ret = ret[i+len(t):]
i = ret.find('>')
gps = ret[:i]
try:
lat, comma, lon = gps.partition(',')
gps = float(lat), float(lon)
except Exception as e:
gps = (None,None)
handler_done = True
return
CLGeocoder = ObjCClass('CLGeocoder').alloc().init()
#print(dir(CLGeocoder))
handler_block = ObjCBlock(handler, restype=None, argtypes=[c_void_p, c_void_p, c_void_p])
CLGeocoder.geocodeAddressString_completionHandler_(ns(address),handler_block)
#geocodeAddressDictionary_preferredLocale_completionHandler_'
# wait handler called and finished
while not handler_done:
time.sleep(0.01)
return gps