-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.py
72 lines (64 loc) · 2.81 KB
/
client.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
from CoreLocation import (CLLocationManager,
CLLocation,
kCLDistanceFilterNone,
kCLLocationAccuracyBest)
from Foundation import (NSRunLoop,
NSDate,
NSObject,
NSBundle)
from suds.client import Client
c = Client('http://localhost:8030/?wsdl')
class LocationClient(NSObject):
is_authorized = CLLocationManager.authorizationStatus()
is_enabled = CLLocationManager.locationServicesEnabled()
def init(self):
"""Define location manager settings for lookups."""
self = super(LocationClient, self).init()
if not self:
return
self.locationManager = CLLocationManager.alloc().init()
self.locationManager.setDelegate_(self)
self.locationManager.setDistanceFilter_(kCLDistanceFilterNone)
self.locationManager.setDesiredAccuracy_(kCLLocationAccuracyBest)
self.locationManager.startUpdatingLocation()
return self
def locationManager_didUpdateToLocation_fromLocation_(self, manager,
newloc, oldloc):
"""Splits location data into separate pieces for processing later."""
lat = newloc.coordinate().latitude
lon = newloc.coordinate().longitude
verAcc = newloc.verticalAccuracy()
horAcc = newloc.horizontalAccuracy()
altitude = newloc.altitude()
time = newloc.timestamp()
gmap = (r"https://www.google.com/maps/place/{0},{1}"
"/@{0},{1},18z/data=!3m1!1e3".format(str(lat), str(lon)))
plist = dict(
Altitude=int(altitude),
CurrentStatus=str("Successful"),
GoogleMap=str(gmap),
LastLocationRun=str(time),
Latitude=str(lat),
LatitudeAccuracy=int(verAcc),
Longitude=str(lon),
LongitudeAccuracy=int(horAcc),
)
c.service.say_hello('ABC234', str(plist['Latitude'])+','+str(plist['Longitude']))
print("Successful lookup request: {0}, {1}".format(
plist['Latitude'], plist['Longitude']))
def locationManager_didFailWithError_(self, manager, err):
"""Handlers errors for location manager."""
if self.is_enabled is True:
if self.is_authorized == 3:
status = "Unable to locate"
if self.is_authorized == 2:
status = "Denied"
if self.is_authorized == 1:
status = "Restricted"
if self.is_authorized == 0:
status = "Not Determined"
else:
status = "Location Services Disabled"
print(status)
finder = LocationClient.alloc().init()
NSRunLoop.currentRunLoop().runUntilDate_(NSDate.dateWithTimeIntervalSinceNow_(5))