Difference between revisions of "User:Saul/nativescript"

From Organic Design wiki
m (npm)
(Maps)
Line 75: Line 75:
 
[https://github.com/dapriett/nativescript-google-maps-sdk The nativescript maps plugin]<br>
 
[https://github.com/dapriett/nativescript-google-maps-sdk The nativescript maps plugin]<br>
 
[https://github.com/naderio/nativescript-google-maps-utils The nativescript maps plugin utils]
 
[https://github.com/naderio/nativescript-google-maps-utils The nativescript maps plugin utils]
=== tns ===
 
<source lang="bash">
 
tns plugin add nativescript-google-maps-sdk # install the maps plugin
 
cp -r node_modules/nativescript-google-maps-sdk/platforms/android/res/values app/App_Resources/Android/src/main/res # copy string templates over
 
</source>
 
Then edit '''app/App_Resources/Android/src/main/res/values/nativescript_google_maps_api.xml''':<br>
 
<source>
 
Remove the comment tags
 
Replace "PUT_API_KEY_HERE" with you api key
 
</source>
 
Insert before the closing application tag in ''' ''':
 
<source lang="html">
 
<meta-data android:name="com.google.android.geo.API_KEY" android:value="@string/nativescript_google_maps_api_key" />
 
</source>
 
You must use the namespace on the pages you wish to use the map on, do this by editing the page tag like so:
 
<source lang="html">
 
<page xmlns:maps="nativescript-google-maps-sdk">
 
<!-- Page content. -->
 
</page>
 
</source>
 
Then you can use the maps tag like so:
 
<source lang="html">
 
<maps:mapView latitude="{{ -36 }}" longitude="{{ 174 }}" />
 
</source>
 
  
=== npm ===
 
 
<source lang="bash">
 
<source lang="bash">
 
npm i nativescript-google-maps-sdk
 
npm i nativescript-google-maps-sdk
Line 123: Line 98:
 
<MapView width="400" height="400" @mapReady="mapReady($event)" :latitude="lat" :longitude="lng" />
 
<MapView width="400" height="400" @mapReady="mapReady($event)" :latitude="lat" :longitude="lng" />
 
</source>
 
</source>
 +
 +
== Geolocation ==
 +
[https://github.com/NativeScript/nativescript-geolocation nativescript-geolocation]

Revision as of 00:44, 11 July 2018

Nativescript is a framework for building native ios and android apps.
Nativescript and vue tutorial

Setup

Firstly ensure that npm is installed.

npm install -g nativescript # Install the nativescript cli

Android

Install

Nativescript install docs

# Install dependencies
sudo apt-get install lib32z1 lib32ncurses5 lib32bz2-1.0 libstdc++6:i386 # Install dependencies
# OR (If you encounter an error showing "Unable to locate package lib32bz2-1.0")
sudo apt-get install lib32z1 lib32ncurses5 libbz2-1.0:i386 libstdc++6:i386
sudo apt-get install g++ # Install the g++ compiler

# Install JDK8/10
sudo apt-get install python-software-properties
sudo add-apt-repository ppa:webupd8team/java
# OR JDK10 (not currently working)
# sudo add-apt-repository ppa:linuxuprising/java
sudo apt-get update
sudo apt install oracle-java8-installer
# OR JDK10 (not currently working)
# sudo apt install oracle-java10-installer
# Set the ENV varible
export JAVA_HOME=$(update-alternatives --query javac | sed -n -e 's/Best: *\(.*\)\/bin\/javac/\1/p')

Download the android sdk tools from https://developer.android.com/studio/#downloads
Extract it in ~/android/sdk

export ANDROID_HOME=~/android/sdk # Set the ANDROID_HOME ENV varible
# Install dependencies
sudo $ANDROID_HOME/tools/bin/sdkmanager "tools" "platform-tools" "platforms;android-25" "build-tools;27.0.3" "extras;android;m2repository" "extras;google;m2repository"

Install Emulator

Nativescript install docs

IOS

To build for IOS you will need a machine running MacOS.
Nativescript MacOS install docs

Webpack Template

Using npm

vue init nativescript-vue/vue-cli-template <project-name>
cd <project-name>
npm install

Using tns

Note: Then tns vue template only supports js files - no vue files.

tns create MyApp --template nativescript-vue-template
cd MyApp
tns run android # run live
tns build android

Project Structure

nativescript-vue/vue-cli-template

dist

The dist/ directory is the directory that nativescript builds the app into.
The built app can be found in dist/platforms/app/build/outputs/apk/debug/app-debug.apk

template

The template/ directory holds the data for the android application like the AndroidManifest.

Usage

Maps

The nativescript maps plugin
The nativescript maps plugin utils

npm i nativescript-google-maps-sdk
cp -r node_modules/nativescript-google-maps-sdk/platforms/android/res/values template/app/App_Resources/Android # copy string templates over

Then edit template/app/App_Resources/Android/values/nativescript_google_maps_api.xml:

Remove the comment tags
Replace "PUT_API_KEY_HERE" with you api key

Insert as is (Do not edit this element!) before the closing application tag in template/app/App_Resources/Android/AndroidManifest.xml:

<meta-data android:name="com.google.android.geo.API_KEY" android:value="@string/nativescript_google_maps_api_key" />

Add these 2 lines in src/main.js to register the component (and yes the import statement is needed):

import { MapViewBase } from 'nativescript-google-maps-sdk/map-view-common';
Vue.registerElement ("MapView", () => require ("nativescript-google-maps-sdk").MapView);

Then you can use the MapView component in your app like so:

<MapView width="400" height="400" @mapReady="mapReady($event)" :latitude="lat" :longitude="lng" />

Geolocation

nativescript-geolocation