Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 98 lines (68 sloc) 3.132 kB
9023c6f last of the references to js-vm from planet
Danny Yoo authored
1 #lang s-exp "../js-vm/base.rkt"
f08f6f6 moving over the phone-specific functions from js-vm to moby
Danny Yoo authored
2
9023c6f last of the references to js-vm from planet
Danny Yoo authored
3 (require "../js-vm/permissions/require-permission.rkt")
4 (require "../js-vm/ffi/ffi.rkt")
5 (require "../js-vm/jsworld/jsworld.rkt")
f08f6f6 moving over the phone-specific functions from js-vm to moby
Danny Yoo authored
6
7
847f236 making the mock location setter
Danny Yoo authored
8 (require "in-phone.rkt"
9 "mock-location-setup.rkt")
6d287f3 about to make mocks
Danny Yoo authored
10
11
07117d7 trying to get latitude and longitude
Danny Yoo authored
12 (provide #;on-location-change!
f08f6f6 moving over the phone-specific functions from js-vm to moby
Danny Yoo authored
13 on-location-change)
14
15
16 (require-permission "PERMISSION:LOCATION")
17
18
07117d7 trying to get latitude and longitude
Danny Yoo authored
19
20 ;; get-geo: -> js-value
21 ;; Gets the geolocation structure.
22 (define (get-geo)
23 (js-get-field (js-get-global-value "navigator")
24 "phonegap_geo"))
25
26
847f236 making the mock location setter
Danny Yoo authored
27
28
5069799 geolocation code cleanup, and exposing the delay as an optional argument
Danny Yoo authored
29 (define on-location-change
30 (case-lambda [(world-updater delay)
31 (cond
32 [(running-in-phone-context?)
b030392 fixing the delay argument, and setting accuracy as a desired criteria
Danny Yoo authored
33 (phonegap-on-location-change world-updater delay)]
5069799 geolocation code cleanup, and exposing the delay as an optional argument
Danny Yoo authored
34 [else
35 (mock-on-location-change world-updater)])]
36 [(world-updater)
37 (on-location-change world-updater 60)]))
38
847f236 making the mock location setter
Danny Yoo authored
39
40
41 (define (mock-on-location-change world-updater)
42 (make-world-config (lambda (location-changed)
43 (mock-location-setup location-changed))
44 (lambda (shutdown-thunk)
45 (shutdown-thunk))
46 (lambda (w lat lng)
87e6fba making the mock location setter; in the context of something without …
Danny Yoo authored
47 (world-updater w
847f236 making the mock location setter
Danny Yoo authored
48 (prim-js->scheme lat)
49 (prim-js->scheme lng)))))
50
51
52
7203fef bumped up to require 1.5 js-vm
Danny Yoo authored
53
5069799 geolocation code cleanup, and exposing the delay as an optional argument
Danny Yoo authored
54 (define (phonegap-on-location-change world-updater delay)
55 (let ([geolocation (get-geo)]
56 [options (js-make-hash)])
57 (js-set-field! options
58 "frequency"
59 (racket->prim-js (* delay 1000)))
60
f08f6f6 moving over the phone-specific functions from js-vm to moby
Danny Yoo authored
61 (make-world-config (lambda (success error)
62 (js-call (js-get-field geolocation "watchPosition")
63 geolocation
64 success
5069799 geolocation code cleanup, and exposing the delay as an optional argument
Danny Yoo authored
65 error
66 options))
f08f6f6 moving over the phone-specific functions from js-vm to moby
Danny Yoo authored
67 (lambda (id) (js-call (js-get-field geolocation "clearWatch")
68 geolocation
69 id))
70 (lambda (w lat lng)
847f236 making the mock location setter
Danny Yoo authored
71 (world-updater w
72 (prim-js->scheme lat)
73 (prim-js->scheme lng)))
f08f6f6 moving over the phone-specific functions from js-vm to moby
Danny Yoo authored
74 (lambda (w e)
847f236 making the mock location setter
Danny Yoo authored
75 (error 'on-location-change "an error occurred with accessing GPS locations")))))
f08f6f6 moving over the phone-specific functions from js-vm to moby
Danny Yoo authored
76
77
78
79
847f236 making the mock location setter
Danny Yoo authored
80 #;(define (on-location-change! world-updater effect-updater)
07117d7 trying to get latitude and longitude
Danny Yoo authored
81 (let ([geolocation (get-geo)])
f08f6f6 moving over the phone-specific functions from js-vm to moby
Danny Yoo authored
82 (make-world-config (lambda (success error)
83 (js-call (js-get-field geolocation "watchPosition")
84 geolocation
85 success
86 error))
87 (lambda (id) (js-call (js-get-field geolocation "clearWatch")
88 geolocation
89 id))
90 (lambda (w lat lng)
847f236 making the mock location setter
Danny Yoo authored
91 (world-with-effects (effect-updater w (prim-js->scheme lat) (prim-js->scheme lng))
92 (world-updater w (prim-js->scheme lat) (prim-js->scheme lng))))
f08f6f6 moving over the phone-specific functions from js-vm to moby
Danny Yoo authored
93 (lambda (w e)
847f236 making the mock location setter
Danny Yoo authored
94 (error 'on-location-change! "an error occurred with accessing GPS locations")))))
95
96
97
Something went wrong with that request. Please try again.