diff --git a/apps/blakus-nativescript/.gitignore b/apps/blakus-nativescript/.gitignore
index 2c6c794..646bfd5 100644
--- a/apps/blakus-nativescript/.gitignore
+++ b/apps/blakus-nativescript/.gitignore
@@ -8,7 +8,6 @@ platforms/
*.js
!eslint.config.js
!webpack.config.js
-!tailwind.config.js
# Logs
logs
diff --git a/apps/blakus-nativescript/App_Resources/Android/src/main/AndroidManifest.xml b/apps/blakus-nativescript/App_Resources/Android/src/main/AndroidManifest.xml
index 2756e53..84664c4 100644
--- a/apps/blakus-nativescript/App_Resources/Android/src/main/AndroidManifest.xml
+++ b/apps/blakus-nativescript/App_Resources/Android/src/main/AndroidManifest.xml
@@ -14,6 +14,9 @@
+
+
+
+
+ "Restaurant"
+ "Pub"
+ "Ice Cream"
+ "Food Court"
+ "Fast Food"
+ "Cafe"
+ "Beer Garden"
+ "Bar"
+ "Blakus"
+ "Blakus"
+ "Blakus"
+
diff --git a/apps/blakus-nativescript/App_Resources/Android/src/main/res/values/strings.xml b/apps/blakus-nativescript/App_Resources/Android/src/main/res/values/strings.xml
new file mode 100644
index 0000000..83a40b2
--- /dev/null
+++ b/apps/blakus-nativescript/App_Resources/Android/src/main/res/values/strings.xml
@@ -0,0 +1,14 @@
+
+
+ "Restorāns"
+ "Krogs"
+ "Saldējums"
+ "Ēdināšanas laukums"
+ "Ātras uzkodas"
+ "Kafejnīca"
+ "Biergarten"
+ "Bārs"
+ "Blakus"
+ "Blakus"
+ "Blakus"
+
diff --git a/apps/blakus-nativescript/package.json b/apps/blakus-nativescript/package.json
index 36a442d..62022dd 100644
--- a/apps/blakus-nativescript/package.json
+++ b/apps/blakus-nativescript/package.json
@@ -4,11 +4,12 @@
"license": "SEE LICENSE IN ",
"repository": "",
"dependencies": {
- "@nativescript/core": "*"
+ "@nativescript/core": "*",
+ "@nativescript/geolocation": "^9.0.0",
+ "@nativescript/localize": "^5.2.0"
},
"devDependencies": {
"@nativescript/android": "~8.8.0",
- "@nativescript/ios": "~8.8.0",
- "@nativescript/tailwind": "^2.1.0"
+ "@nativescript/ios": "~8.8.0"
}
}
diff --git a/apps/blakus-nativescript/src/app.css b/apps/blakus-nativescript/src/app.css
index e02abfc..ec2684e 100644
--- a/apps/blakus-nativescript/src/app.css
+++ b/apps/blakus-nativescript/src/app.css
@@ -1 +1,7 @@
-
+.ns-root {
+ --base-color: red;
+}
+
+Button {
+ background-color: var(--base-color);
+}
\ No newline at end of file
diff --git a/apps/blakus-nativescript/src/app.ts b/apps/blakus-nativescript/src/app.ts
index a4c5c52..2275cac 100644
--- a/apps/blakus-nativescript/src/app.ts
+++ b/apps/blakus-nativescript/src/app.ts
@@ -1,3 +1,7 @@
import { Application } from '@nativescript/core';
+import { localize } from '@nativescript/localize';
+
+Application.setResources({ L: localize })
Application.run({ moduleName: 'app-root' });
+console.log(localize('app.name'));
\ No newline at end of file
diff --git a/apps/blakus-nativescript/src/i18n/en.json b/apps/blakus-nativescript/src/i18n/en.json
new file mode 100644
index 0000000..af22dc5
--- /dev/null
+++ b/apps/blakus-nativescript/src/i18n/en.json
@@ -0,0 +1,13 @@
+{
+ "app.name": "Blakus",
+ "amenity": {
+ "bar": "Bar",
+ "biergarten": "Beer Garden",
+ "cafe": "Cafe",
+ "fast_food": "Fast Food",
+ "food_court": "Food Court",
+ "ice_cream": "Ice Cream",
+ "pub": "Pub",
+ "restaurant": "Restaurant"
+ }
+}
\ No newline at end of file
diff --git a/apps/blakus-nativescript/src/i18n/lv.default.json b/apps/blakus-nativescript/src/i18n/lv.default.json
new file mode 100644
index 0000000..2079b73
--- /dev/null
+++ b/apps/blakus-nativescript/src/i18n/lv.default.json
@@ -0,0 +1,13 @@
+{
+ "app.name": "Blakus",
+ "amenity": {
+ "bar": "Bārs",
+ "biergarten": "Biergarten",
+ "cafe": "Kafejnīca",
+ "fast_food": "Ātras uzkodas",
+ "food_court": "Ēdināšanas laukums",
+ "ice_cream": "Saldējums",
+ "pub": "Krogs",
+ "restaurant": "Restorāns"
+ }
+}
\ No newline at end of file
diff --git a/apps/blakus-nativescript/src/location.ts b/apps/blakus-nativescript/src/location.ts
new file mode 100644
index 0000000..87e80bc
--- /dev/null
+++ b/apps/blakus-nativescript/src/location.ts
@@ -0,0 +1,32 @@
+import * as geolocation from '@nativescript/geolocation';
+import { CoreTypes } from '@nativescript/core'
+
+export class DeviceLocation {
+ static async getDeviceLocation() {
+ try {
+
+ // Enable location services
+ await geolocation.enableLocationRequest(false, true);
+
+ const enabled = await geolocation.isEnabled();
+
+ console.log('what do we got?', enabled)
+
+ // Get the current location
+ const location = await geolocation.getCurrentLocation({
+ desiredAccuracy: CoreTypes.Accuracy.high,
+ maximumAge: 5000,
+ timeout: 20000,
+ });
+
+ if (location) {
+ console.log(`Latitude: ${location.latitude}, Longitude: ${location.longitude}`);
+ return location;
+ } else {
+ throw new Error('Could not get the location.');
+ }
+ } catch (error) {
+ console.error('Error obtaining location:', error);
+ }
+ }
+}
\ No newline at end of file
diff --git a/apps/blakus-nativescript/src/main-page.xml b/apps/blakus-nativescript/src/main-page.xml
index 5970ee7..4f0c4ef 100644
--- a/apps/blakus-nativescript/src/main-page.xml
+++ b/apps/blakus-nativescript/src/main-page.xml
@@ -1,11 +1,22 @@
-
+
-
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/apps/blakus-nativescript/src/main-view-model.ts b/apps/blakus-nativescript/src/main-view-model.ts
index 27cf753..167d6f8 100644
--- a/apps/blakus-nativescript/src/main-view-model.ts
+++ b/apps/blakus-nativescript/src/main-view-model.ts
@@ -1,8 +1,53 @@
-import { Observable } from '@nativescript/core';
+import { Observable, Http, type ItemEventData, ListView } from '@nativescript/core';
+import { DeviceLocation } from './location';
+import type { Location } from '@nativescript/geolocation';
+import { localize } from '@nativescript/localize';
+
+type ReverseGeocodeResult = {
+ valsts: string;
+ admin_vien: string;
+ terit_vien: string;
+ apdz_vieta: string;
+ iela: string;
+ maja: string;
+ index: string;
+ korpus: string;
+ vzd_id: string;
+ distance: number;
+ x: string;
+ y: string;
+ lon: number;
+ lat: number;
+ adrese: string;
+}
+
+type BlakusItem = {
+ title: string;
+ amenity: string;
+ tags: Record;
+}
+
+type OverpassResult = {
+ version: number;
+ generator: string;
+ osm3s: Record;
+ elements: {
+ type: string,
+ id: number,
+ tags: Record;
+ }[]
+}
+
+async function aWait(timeout: number) {
+ return new Promise(resolve => setTimeout(resolve, timeout));
+}
export class HelloWorldModel extends Observable {
private _counter: number;
private _message: string;
+ private _items: BlakusItem[];
+ private _locationServiceBaseURL = 'https://api.kartes.lv/v3/KVDM_mwwKi/'
+ private _overpassBaseURL = 'https://overpass-api.de/api/';
constructor() {
super();
@@ -23,17 +68,115 @@ export class HelloWorldModel extends Observable {
}
}
- onTap() {
- this._counter--;
- this.updateMessage();
+ get items(): BlakusItem[] {
+ return this._items || [];
}
- private updateMessage() {
- if (this._counter <= 0) {
- this.message =
- 'Hoorraaay! You unlocked the NativeScript clicker achievement!';
- } else {
- this.message = `${this._counter} taps left`;
+ set items(value: BlakusItem[]) {
+ if (this._items !== value) {
+ this._items = value;
+ this.notifyPropertyChange('items', value);
}
}
+
+ async reverseGeocode({latitude, longitude}: Location) {
+ const params = new URLSearchParams();
+ params.set('lat', latitude.toString());
+ params.set('lon', longitude.toString());
+
+ this.message = [latitude, longitude].join(', ');
+
+ const url = new URL(`reverse_geocoding?${params}`, this._locationServiceBaseURL).toString();
+ const result = await Http.getJSON(url);
+ console.log(result);
+
+ return result;
+ }
+
+ overpassQuery(query: string) {
+ const url = new URL(`interpreter?data=${encodeURIComponent(query)}`, this._overpassBaseURL).toString();
+ console.log('overpass query', url)
+ return Http.getJSON(url)
+ }
+
+ async getOverpassAmenities({latitude, longitude}: Location) {
+ const radius = 1000; // meters
+ const query = `
+ [out:json][timeout:25];
+ node["amenity"](around:${radius}, ${latitude}, ${longitude});
+ out tags;
+ `;
+ const result = await this.overpassQuery(query);
+ console.log('yep');
+ console.log(Array.from(new Set(result.elements.map(el => el.tags['amenity']))));
+ }
+
+ async getOverpassInfo({latitude, longitude}: Location) {
+
+ const radius = 1000; // meters
+ const amenities = ['restaurant', 'cafe', 'bar', 'pub', 'biergarten', 'fast_food', 'food_court', 'ice_cream'];
+
+ const query = `
+ [out:json];
+ node(around:${radius}, ${latitude}, ${longitude})["amenity"~"${amenities.join('|')}"];
+ out body;
+ >;
+ out skel qt;
+ `;
+
+ const result = await this.overpassQuery(query);
+ this.items = result.elements
+ .map(({ tags }) => ({ title: tags.name, amenity: tags.amenity, tags}))
+ .filter(i => amenities.includes(i.amenity)); // query returns some random results. need to look into this
+
+ console.log(localize('app.name'))
+
+ console.log(result.elements);
+ }
+
+ async postalPolygons(country = 'LV', code: string, mode: 'isolate' | 'collect' | 'union' = 'union') {
+ await aWait(1000);
+ const params = new URLSearchParams();
+ if (code.length === 4) params.set('search', `${country}-${code}`);
+ if (code.length == 2) params.set('groups', `${country}-${code}`)
+ params.set('union_mode', mode);
+ params.set('wgs84', '');
+ // params.set('wkt', '');
+ const url = new URL(`postal_codes?${params}`, this._locationServiceBaseURL).toString();
+
+ const result = await Http.getJSON(url);
+ console.log(url);
+ console.log(result);
+
+ }
+
+ async onLocationTap() {
+ const location = await DeviceLocation.getDeviceLocation();
+ await this.getOverpassInfo(location);
+ // await this.getOverpassAmenities(location);
+ // const { index } = await this.reverseGeocode(location);
+ // const [country, code] = index.split('-');
+ // await this.postalPolygons(country, code);
+
+
+ }
+
+ onTap() {
+ this._counter--;
+
+ if (this._counter <= 0) {
+ this.updateMessage('Hoorraaay! You unlocked the NativeScript clicker achievement!');
+ } else {
+ this.updateMessage(`${this._counter} taps left`);
+ }
+ }
+
+ onItemTap(args: ItemEventData) {
+ const listView = args.object as ListView
+ console.log('Tapped item', listView.items[args.index])
+ }
+
+ private updateMessage(message = "") {
+ this.message = message;
+ }
}
diff --git a/apps/blakus-nativescript/tailwind.config.js b/apps/blakus-nativescript/tailwind.config.js
deleted file mode 100644
index f8cfdb1..0000000
--- a/apps/blakus-nativescript/tailwind.config.js
+++ /dev/null
@@ -1,13 +0,0 @@
-/** @type {import('tailwindcss').Config} */
-module.exports = {
- content: ['./src/**/*.{css,xml,html,vue,svelte,ts,tsx}'],
- // use the .ns-dark class to control dark mode (applied by NativeScript) - since 'media' (default) is not supported.
- darkMode: ['class', '.ns-dark'],
- theme: {
- extend: {},
- },
- plugins: [],
- corePlugins: {
- preflight: false, // disables browser-specific resets
- },
-};