เริ่มต้นการใช้งาน
React Native
Setting Up (Expo)
Install & init projectnpm install -g expo-cli expo init <project name> cd <project name> expo install react-native-webview npm install sphere-react-native
script
Config babel.config.js
module.exports = function(api) { api.cache(true); return { presets: [ 'babel-preset-expo', ['@babel/preset-env', { "targets": "iOS >= 11, Android >= 56" }], ], }; };
Config app.json
Then, Register BUNDLE_ID, PACKAGE_NAME at https://sphere.gistda.or.th/ to obtain API_KEY "ios": { "bundleIdentifier": "BUNDLE_ID", ... "android": { "package": "PACKAGE_NAME",
Setting Up (Native)
Follow React Native CLI Quickstart instruction and runnpm install react-native-webview sphere-react-native npm install -D @babel/preset-env
script
Config babel.config.js
presets: [ 'module:metro-react-native-babel-preset', ['@babel/preset-env', { "targets": "iOS >= 11, Android >= 56" }], ],
javascript
From app.json
Register PROJECT_NAME at https://sphere.gistda.or.th/ to obtain API_KEY"name": PROJECT_NAME,
javascript
Getting Started
Add MapView in App.js
In main App functionimport Sphere from 'sphere-react-native';
javascript
Sphere.apiKey = 'API_KEY';
javascript
If module fail to auto-detect app's bundle ID, add
Sphere.bundleId = 'REGISTERED_ID';
Under root View<Sphere.MapView />
javascriptIn StyleSheet
alignItems: 'stretch'
javascriptFor complete file, see example/App.js
Run in Simulator
npm run ios npm run android
script