@maccesar/titools 5.3.0 → 5.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CONTRIBUTING.md +1 -1
- package/README.md +31 -60
- package/agents/ti-pro.md +3 -1
- package/commands/ti-audit.md +6 -4
- package/docs/examples.md +9 -0
- package/docs/knowledge-index.md +2 -1
- package/lib/config.js +1 -0
- package/package.json +1 -1
- package/skills/alloy-guides/SKILL.md +18 -179
- package/skills/alloy-guides/references/CLI_TASKS.md +17 -216
- package/skills/alloy-guides/references/CONCEPTS.md +27 -162
- package/skills/alloy-guides/references/CONTROLLERS.md +38 -236
- package/skills/alloy-guides/references/MODELS.md +47 -723
- package/skills/alloy-guides/references/MODELS_ADVANCED.md +21 -482
- package/skills/alloy-guides/references/VIEWS_DYNAMIC.md +12 -222
- package/skills/alloy-guides/references/VIEWS_STYLES.md +39 -358
- package/skills/alloy-guides/references/VIEWS_XML.md +36 -552
- package/skills/alloy-guides/references/WIDGETS.md +49 -127
- package/skills/alloy-howtos/SKILL.md +14 -169
- package/skills/alloy-howtos/references/best_practices.md +9 -113
- package/skills/alloy-howtos/references/cli_reference.md +18 -223
- package/skills/alloy-howtos/references/config_files.md +50 -133
- package/skills/alloy-howtos/references/debugging_troubleshooting.md +19 -63
- package/skills/alloy-howtos/references/samples.md +21 -138
- package/skills/ti-api/SKILL.md +10 -2
- package/skills/ti-api/references/api-android.md +36 -2
- package/skills/ti-api/references/api-app-platform.md +39 -3
- package/skills/ti-api/references/api-core.md +50 -18
- package/skills/ti-api/references/api-data-network.md +49 -35
- package/skills/ti-api/references/api-media.md +45 -27
- package/skills/ti-api/references/api-services.md +39 -9
- package/skills/ti-api/references/api-ui-android.md +33 -13
- package/skills/ti-api/references/api-ui-extras.md +41 -15
- package/skills/ti-api/references/api-ui-ios-animator.md +42 -26
- package/skills/ti-api/references/api-ui-ios.md +74 -2
- package/skills/ti-api/references/api-ui-lists.md +32 -16
- package/skills/ti-api/references/api-ui-text-input.md +34 -17
- package/skills/ti-api/references/api-ui-views.md +27 -1
- package/skills/ti-api/references/api-ui-windows-navigation.md +32 -18
- package/skills/ti-api/references/api-xml-global.md +66 -16
- package/skills/ti-create-release/SKILL.md +98 -0
- package/skills/ti-create-release/references/module-discovery.md +69 -0
- package/skills/ti-expert/references/adaptive-layouts.md +1 -1
- package/skills/ti-guides/SKILL.md +37 -76
- package/skills/ti-guides/references/advanced-data-and-images.md +122 -126
- package/skills/ti-guides/references/android-manifest.md +24 -83
- package/skills/ti-guides/references/app-distribution.md +31 -377
- package/skills/ti-guides/references/application-frameworks.md +127 -335
- package/skills/ti-guides/references/cli-reference.md +184 -633
- package/skills/ti-guides/references/commonjs-advanced.md +81 -231
- package/skills/ti-guides/references/compatibility-matrix.md +36 -75
- package/skills/ti-guides/references/hello-world.md +95 -70
- package/skills/ti-guides/references/hyperloop-native-access.md +52 -448
- package/skills/ti-guides/references/resources.md +174 -142
- package/skills/ti-guides/references/sdk-release-notes.md +28 -71
- package/skills/ti-guides/references/tiapp-config.md +222 -598
- package/skills/ti-howtos/SKILL.md +23 -123
- package/skills/ti-howtos/references/cross-platform-development.md +119 -324
- package/skills/ti-howtos/references/debugging-profiling.md +77 -445
- package/skills/ti-howtos/references/extending-titanium.md +199 -673
- package/skills/ti-howtos/references/local-data-sources.md +87 -300
- package/skills/ti-howtos/references/location-and-maps.md +86 -213
- package/skills/ti-howtos/references/media-apis.md +103 -223
- package/skills/ti-howtos/references/notification-services.md +86 -506
- package/skills/ti-howtos/references/remote-data-sources.md +97 -316
- package/skills/ti-howtos/references/using-modules.md +77 -133
- package/skills/ti-ui/SKILL.md +28 -143
- package/skills/ti-ui/references/icons-and-splash-screens.md +74 -403
- package/skills/ti-ui/references/layouts-and-positioning.md +175 -402
- package/skills/ti-ui/references/listviews-and-performance.md +100 -703
- package/skills/ti-ui/references/platform-conventions.md +180 -0
- package/skills/ti-ui/references/user-interface.md +43 -0
- package/skills/alloy-guides/references/VIEWS_WITHOUT_CONTROLLERS.md +0 -102
- package/skills/alloy-howtos/references/custom_tags.md +0 -148
- package/skills/ti-guides/references/coding-best-practices.md +0 -149
- package/skills/ti-guides/references/javascript-primer.md +0 -414
- package/skills/ti-guides/references/reserved-words.md +0 -36
- package/skills/ti-guides/references/style-and-conventions.md +0 -103
- package/skills/ti-howtos/references/android-platform-deep-dives.md +0 -624
- package/skills/ti-howtos/references/automation-fastlane-appium.md +0 -96
- package/skills/ti-howtos/references/buffer-codec-streams.md +0 -162
- package/skills/ti-howtos/references/google-maps-v2.md +0 -172
- package/skills/ti-howtos/references/ios-map-kit.md +0 -149
- package/skills/ti-howtos/references/ios-platform-deep-dives.md +0 -611
- package/skills/ti-howtos/references/tutorials.md +0 -565
- package/skills/ti-howtos/references/web-content-integration.md +0 -287
- package/skills/ti-howtos/references/webpack-build-pipeline.md +0 -124
- package/skills/ti-ui/references/accessibility-deep-dive.md +0 -288
- package/skills/ti-ui/references/animation-and-matrices.md +0 -569
- package/skills/ti-ui/references/application-structures.md +0 -626
- package/skills/ti-ui/references/custom-fonts-styling.md +0 -549
- package/skills/ti-ui/references/event-handling.md +0 -401
- package/skills/ti-ui/references/gestures.md +0 -448
- package/skills/ti-ui/references/orientation.md +0 -374
- package/skills/ti-ui/references/platform-ui-android.md +0 -727
- package/skills/ti-ui/references/platform-ui-ios.md +0 -576
- package/skills/ti-ui/references/scrolling-views.md +0 -288
- package/skills/ti-ui/references/tableviews.md +0 -542
|
@@ -1,266 +1,139 @@
|
|
|
1
|
-
# Location
|
|
1
|
+
# Location & maps
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Based on the [current official guide](https://titaniumsdk.com/docs/build/location.md). Examples target released SDK 13.4.1; verify the selected SDK before adopting version-specific behavior.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
Location needs permission, and the permission has kinds: while-in-use or
|
|
6
|
+
always, and on iOS precise or approximate. Ask for the least you need.
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
iOS accuracy levels:
|
|
11
|
-
- `ACCURACY_BEST` - highest power (GPS)
|
|
12
|
-
- `ACCURACY_NEAREST_TEN_METERS` - medium-high power
|
|
13
|
-
- `ACCURACY_HUNDRED_METERS` - medium power
|
|
14
|
-
- `ACCURACY_KILOMETER` - low power
|
|
15
|
-
- `ACCURACY_THREE_KILOMETERS` - lowest power (cell/wifi)
|
|
16
|
-
|
|
17
|
-
Key properties:
|
|
18
|
-
```javascript
|
|
19
|
-
Ti.Geolocation.accuracy = Ti.Geolocation.ACCURACY_BEST;
|
|
20
|
-
Ti.Geolocation.distanceFilter = 10; // meters - only fire if moved X meters
|
|
21
|
-
Ti.Geolocation.headingFilter = 5; // degrees - only fire if heading changed X degrees
|
|
22
|
-
Ti.Geolocation.preferredProvider = Ti.Geolocation.PROVIDER_GPS; // or PROVIDER_NETWORK
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
Note: on many Android devices, a low-precision passive location provider is always enabled, even when the user disables GPS and Network providers. `Ti.Geolocation.locationServicesEnabled` may always return `true` on those devices.
|
|
26
|
-
|
|
27
|
-
### Android configuration modes
|
|
28
|
-
|
|
29
|
-
Simple mode (ACCURACY_HIGH/LOW):
|
|
30
|
-
```javascript
|
|
31
|
-
Ti.Geolocation.accuracy = Ti.Geolocation.ACCURACY_HIGH;
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
Manual mode (fine-grained control):
|
|
35
|
-
```javascript
|
|
36
|
-
const providerGps = Ti.Geolocation.Android.createLocationProvider({
|
|
37
|
-
name: Ti.Geolocation.PROVIDER_GPS,
|
|
38
|
-
minUpdateDistance: 0.0,
|
|
39
|
-
minUpdateTime: 0
|
|
40
|
-
});
|
|
41
|
-
Ti.Geolocation.Android.addLocationProvider(providerGps);
|
|
42
|
-
Ti.Geolocation.Android.manualMode = true;
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
### Location permissions
|
|
46
|
-
|
|
47
|
-
```javascript
|
|
48
|
-
// Check permissions
|
|
49
|
-
if (Ti.Geolocation.hasLocationPermissions(Ti.Geolocation.AUTHORIZATION_WHEN_IN_USE)) {
|
|
50
|
-
startTracking();
|
|
51
|
-
} else {
|
|
8
|
+
```js
|
|
9
|
+
if (!Ti.Geolocation.hasLocationPermissions(Ti.Geolocation.AUTHORIZATION_WHEN_IN_USE)) {
|
|
52
10
|
Ti.Geolocation.requestLocationPermissions(Ti.Geolocation.AUTHORIZATION_WHEN_IN_USE, (e) => {
|
|
53
11
|
if (e.success) {
|
|
54
|
-
|
|
55
|
-
} else {
|
|
56
|
-
Ti.API.error(`Permission denied: ${e.error}`);
|
|
12
|
+
locate();
|
|
57
13
|
}
|
|
58
14
|
});
|
|
15
|
+
} else {
|
|
16
|
+
locate();
|
|
59
17
|
}
|
|
60
18
|
```
|
|
61
19
|
|
|
62
|
-
|
|
20
|
+
`tiapp.xml` needs the matching usage string on iOS:
|
|
21
|
+
|
|
63
22
|
```xml
|
|
64
|
-
<
|
|
65
|
-
<
|
|
66
|
-
|
|
67
|
-
<key>
|
|
68
|
-
<string>
|
|
23
|
+
<ios>
|
|
24
|
+
<plist>
|
|
25
|
+
<dict>
|
|
26
|
+
<key>NSLocationWhenInUseUsageDescription</key>
|
|
27
|
+
<string>Show which notes were written near you.</string>
|
|
28
|
+
</dict>
|
|
29
|
+
</plist>
|
|
30
|
+
</ios>
|
|
69
31
|
```
|
|
70
32
|
|
|
71
|
-
|
|
33
|
+
Asking for `AUTHORIZATION_ALWAYS` is a much bigger request, is reviewed harder,
|
|
34
|
+
and on iOS the user is asked again later whether they meant it. Do not request
|
|
35
|
+
it for a feature that works while the app is open.
|
|
72
36
|
|
|
73
|
-
|
|
37
|
+
## One position
|
|
74
38
|
|
|
75
|
-
```
|
|
76
|
-
|
|
39
|
+
```js
|
|
40
|
+
function locate() {
|
|
77
41
|
Ti.Geolocation.getCurrentPosition((e) => {
|
|
78
|
-
if (e.
|
|
79
|
-
Ti.API.error(`
|
|
80
|
-
|
|
81
|
-
const coords = e.coords;
|
|
82
|
-
// { latitude, longitude, altitude, accuracy, heading, speed, timestamp }
|
|
42
|
+
if (!e.success) {
|
|
43
|
+
Ti.API.error(`location failed: ${e.error}`);
|
|
44
|
+
return;
|
|
83
45
|
}
|
|
46
|
+
const { latitude, longitude, accuracy } = e.coords;
|
|
47
|
+
Ti.API.info(`${latitude}, ${longitude} +/- ${accuracy}m`);
|
|
84
48
|
});
|
|
85
49
|
}
|
|
86
50
|
```
|
|
87
51
|
|
|
88
|
-
|
|
52
|
+
`accuracy` on the result is a radius in metres, and it is the number that
|
|
53
|
+
decides whether a fix is usable. A first fix indoors can be several hundred
|
|
54
|
+
metres wide; treat anything above your tolerance as "not yet" rather than as an
|
|
55
|
+
answer.
|
|
89
56
|
|
|
90
|
-
|
|
91
|
-
Ti.Geolocation.addEventListener('location', (e) => {
|
|
92
|
-
if (e.error) {
|
|
93
|
-
Ti.API.error(`Error: ${e.error}`);
|
|
94
|
-
} else {
|
|
95
|
-
Ti.API.info(`${e.coords.latitude}, ${e.coords.longitude}`);
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
```
|
|
99
|
-
|
|
100
|
-
### Lifecycle management (critical for battery)
|
|
101
|
-
|
|
102
|
-
Android Activity events:
|
|
103
|
-
```javascript
|
|
104
|
-
let locationAdded = false;
|
|
105
|
-
const handleLocation = (e) => {
|
|
106
|
-
if (!e.error) {
|
|
107
|
-
Ti.API.info(e.coords);
|
|
108
|
-
}
|
|
109
|
-
};
|
|
57
|
+
## Tracking
|
|
110
58
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
locationAdded = true;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
59
|
+
```js
|
|
60
|
+
Ti.Geolocation.accuracy = Ti.Geolocation.ACCURACY_HIGH;
|
|
61
|
+
Ti.Geolocation.distanceFilter = 10;
|
|
117
62
|
|
|
118
|
-
function
|
|
119
|
-
if (
|
|
120
|
-
|
|
121
|
-
locationAdded = false;
|
|
63
|
+
function onLocation(e) {
|
|
64
|
+
if (!e.success) {
|
|
65
|
+
return;
|
|
122
66
|
}
|
|
67
|
+
Ti.API.info(`moved to ${e.coords.latitude}, ${e.coords.longitude}`);
|
|
123
68
|
}
|
|
124
69
|
|
|
125
|
-
|
|
126
|
-
addHandler();
|
|
127
|
-
|
|
128
|
-
const activity = Ti.Android.currentActivity;
|
|
129
|
-
activity.addEventListener('destroy', removeHandler);
|
|
130
|
-
activity.addEventListener('pause', removeHandler); // Stop when in background
|
|
131
|
-
activity.addEventListener('resume', addHandler); // Resume when foreground
|
|
70
|
+
Ti.Geolocation.addEventListener('location', onLocation);
|
|
132
71
|
```
|
|
133
72
|
|
|
134
|
-
|
|
73
|
+
`distanceFilter` is metres of movement before another event, and it is the
|
|
74
|
+
single most effective thing you can set: without it you get an event per fix,
|
|
75
|
+
which is a battery complaint waiting to happen.
|
|
135
76
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
Ti.Geolocation.getCurrentHeading((e) => {
|
|
139
|
-
Ti.API.info(e.heading.magneticHeading); // degrees from magnetic north
|
|
140
|
-
Ti.API.info(e.heading.trueHeading); // degrees from true north
|
|
141
|
-
});
|
|
77
|
+
**Remove the listener when the screen goes away.** Location updates continue
|
|
78
|
+
while a listener is attached, whether or not anything is looking at them.
|
|
142
79
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
Ti.API.info(`Heading: ${e.heading.magneticHeading}`);
|
|
147
|
-
}
|
|
80
|
+
```js
|
|
81
|
+
win.addEventListener('close', () => {
|
|
82
|
+
Ti.Geolocation.removeEventListener('location', onLocation);
|
|
148
83
|
});
|
|
149
84
|
```
|
|
150
85
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
- `heading.trueHeading` - degrees relative to true north (requires location)
|
|
154
|
-
- `heading.accuracy` - deviation in degrees (lower is better)
|
|
155
|
-
- `heading.x`, `heading.y`, `heading.z` - raw magnetometer data (microteslas)
|
|
86
|
+
Set `accuracy` to the loosest value that works. `ACCURACY_HIGH` powers the GPS
|
|
87
|
+
radio; a "which city" feature does not need it.
|
|
156
88
|
|
|
157
|
-
##
|
|
89
|
+
## Addresses
|
|
158
90
|
|
|
159
|
-
|
|
91
|
+
`reverseGeocoder` turns coordinates into an address and `forwardGeocoder` does
|
|
92
|
+
the reverse. Both are network calls against a platform service, so they fail
|
|
93
|
+
offline and are rate limited:
|
|
160
94
|
|
|
161
|
-
```
|
|
162
|
-
Ti.Geolocation.
|
|
163
|
-
if (e.success) {
|
|
164
|
-
Ti.API.info(
|
|
95
|
+
```js
|
|
96
|
+
Ti.Geolocation.reverseGeocoder(latitude, longitude, (e) => {
|
|
97
|
+
if (e.success && e.places.length) {
|
|
98
|
+
Ti.API.info(e.places[0].address);
|
|
165
99
|
}
|
|
166
100
|
});
|
|
167
101
|
```
|
|
168
102
|
|
|
169
|
-
|
|
170
|
-
```javascript
|
|
171
|
-
Ti.Geolocation.forwardGeocoder('1600 Amphitheatre Pkwy, Mountain View, CA', (e) => {
|
|
172
|
-
if (!e.success || e.error) {
|
|
173
|
-
Ti.API.error(`Geocoding failed: ${e.error}`);
|
|
174
|
-
return;
|
|
175
|
-
}
|
|
176
|
-
Ti.API.info(`Lat: ${e.latitude}, Lng: ${e.longitude}`);
|
|
177
|
-
});
|
|
178
|
-
```
|
|
179
|
-
|
|
180
|
-
### Reverse geocoding (coordinates → places)
|
|
181
|
-
|
|
182
|
-
```javascript
|
|
183
|
-
Ti.Geolocation.reverseGeocoder(37.389569, -122.050212, (e) => {
|
|
184
|
-
if (e.success) {
|
|
185
|
-
e.places.forEach((place) => {
|
|
186
|
-
Ti.API.info(place.address); // Full address
|
|
187
|
-
Ti.API.info(place.city); // City name
|
|
188
|
-
Ti.API.info(place.country); // Country
|
|
189
|
-
Ti.API.info(place.zipcode); // Postal code
|
|
190
|
-
});
|
|
191
|
-
}
|
|
192
|
-
});
|
|
193
|
-
```
|
|
194
|
-
|
|
195
|
-
## 2. Native maps (platform-specific details)
|
|
196
|
-
|
|
197
|
-
Due to the complexity of modern native maps, refer to the detailed guides:
|
|
198
|
-
|
|
199
|
-
- Google Maps v2 for Android: `google-maps-v2.md`
|
|
200
|
-
- iOS Map Kit: `ios-map-kit.md`
|
|
201
|
-
|
|
202
|
-
## Common map patterns
|
|
203
|
-
|
|
204
|
-
### Add annotation after map creation
|
|
103
|
+
## Maps
|
|
205
104
|
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
```
|
|
209
|
-
|
|
210
|
-
### Remove annotation
|
|
211
|
-
|
|
212
|
-
```javascript
|
|
213
|
-
mapview.removeAnnotation(annotation);
|
|
214
|
-
```
|
|
215
|
-
|
|
216
|
-
### Remove all annotations
|
|
217
|
-
|
|
218
|
-
```javascript
|
|
219
|
-
mapview.removeAllAnnotations();
|
|
220
|
-
```
|
|
105
|
+
Maps are **not** in the core SDK. `ti.map` is a module, maintained by TiDev,
|
|
106
|
+
and it wraps Google Maps on Android and MapKit on iOS.
|
|
221
107
|
|
|
222
|
-
### Select annotation programmatically
|
|
223
|
-
|
|
224
|
-
```javascript
|
|
225
|
-
mapview.selectAnnotation(annotation);
|
|
226
108
|
```
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
mapview.deselectAnnotation(annotation);
|
|
109
|
+
<modules>
|
|
110
|
+
<module platform="android">ti.map</module>
|
|
111
|
+
<module platform="iphone">ti.map</module>
|
|
112
|
+
</modules>
|
|
232
113
|
```
|
|
233
114
|
|
|
234
|
-
|
|
115
|
+
```js
|
|
116
|
+
const Map = require('ti.map');
|
|
235
117
|
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
latitude:
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
// Or for region
|
|
244
|
-
mapview.setRegion({
|
|
245
|
-
latitude: 37.389569,
|
|
246
|
-
longitude: -122.050212,
|
|
247
|
-
latitudeDelta: 0.05,
|
|
248
|
-
longitudeDelta: 0.05,
|
|
249
|
-
animate: true
|
|
118
|
+
const view = Map.createView({
|
|
119
|
+
mapType: Map.NORMAL_TYPE,
|
|
120
|
+
region: { latitude: 51.5, longitude: -0.12, latitudeDelta: 0.05, longitudeDelta: 0.05 },
|
|
121
|
+
annotations: [
|
|
122
|
+
Map.createAnnotation({ latitude: 51.5, longitude: -0.12, title: 'Here' })
|
|
123
|
+
]
|
|
250
124
|
});
|
|
125
|
+
win.add(view);
|
|
251
126
|
```
|
|
252
127
|
|
|
253
|
-
|
|
128
|
+
Android additionally needs a Google Maps API key in `tiapp.xml`, and a build
|
|
129
|
+
without one shows an empty grid rather than an error. If your map is blank grey
|
|
130
|
+
squares, that is the reason.
|
|
254
131
|
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
132
|
+
See [using modules](https://titaniumsdk.com/docs/build/modules.md) for installing it, and the module's
|
|
133
|
+
own reference for the full API.
|
|
134
|
+
|
|
135
|
+

|
|
258
136
|
|
|
259
|
-
|
|
137
|
+
## Next
|
|
260
138
|
|
|
261
|
-
|
|
262
|
-
2. Accuracy: use the lowest accuracy that meets your needs.
|
|
263
|
-
3. Permissions: check permissions before requesting location. Handle denial gracefully.
|
|
264
|
-
4. Maps on Android: only one map view per application (legacy). Use `ti.map` for multiple views.
|
|
265
|
-
5. API keys: Google Maps API key required for Android (debug and production).
|
|
266
|
-
6. User location: requires location permissions (`NSLocationWhenInUseUsageDescription` for iOS).
|
|
139
|
+
[Notifications](https://titaniumsdk.com/docs/build/notifications.md) covers local and push.
|