|
| 1 | +# NativeScript Firebase plugin |
| 2 | + |
| 3 | +The leading realtime database. |
| 4 | + |
| 5 | +Android SDK downloaded from: https://www.firebase.com/docs/android/api/ |
| 6 | + |
| 7 | +emulation commands: |
| 8 | + |
| 9 | +tns emulate ios --device iPhone-6s |
| 10 | + |
| 11 | +**TODO all below.** |
| 12 | + |
| 13 | + |
| 14 | + |
| 15 | + |
| 16 | + |
| 17 | + |
| 18 | + |
| 19 | + |
| 20 | + |
| 21 | + |
| 22 | + |
| 23 | + |
| 24 | + |
| 25 | + |
| 26 | + |
| 27 | + |
| 28 | + |
| 29 | + |
| 30 | + |
| 31 | + |
| 32 | + |
| 33 | + |
| 34 | + |
| 35 | + |
| 36 | + |
| 37 | + |
| 38 | + |
| 39 | + |
| 40 | + |
| 41 | + |
| 42 | + |
| 43 | + |
| 44 | + |
| 45 | + |
| 46 | + |
| 47 | + |
| 48 | + |
| 49 | + |
| 50 | + |
| 51 | + |
| 52 | + |
| 53 | + |
| 54 | + |
| 55 | + |
| 56 | + |
| 57 | + |
| 58 | + |
| 59 | + |
| 60 | + |
| 61 | + |
| 62 | + |
| 63 | + |
| 64 | + |
| 65 | + |
| 66 | + |
| 67 | + |
| 68 | + |
| 69 | + |
| 70 | + |
| 71 | + |
| 72 | + |
| 73 | + |
| 74 | + |
| 75 | + |
| 76 | + |
| 77 | + |
| 78 | + |
| 79 | + |
| 80 | + |
| 81 | + |
| 82 | + |
| 83 | + |
| 84 | + |
| 85 | + |
| 86 | + |
| 87 | + |
| 88 | + |
| 89 | + |
| 90 | + |
| 91 | + |
| 92 | + |
| 93 | + |
| 94 | + |
| 95 | + |
| 96 | + |
| 97 | + |
| 98 | + |
| 99 | + |
| 100 | + |
| 101 | + |
| 102 | + |
| 103 | + |
| 104 | + |
| 105 | + |
| 106 | + |
| 107 | + |
| 108 | + |
| 109 | + |
| 110 | + |
| 111 | + |
| 112 | + |
| 113 | + |
| 114 | + |
| 115 | + |
| 116 | + |
| 117 | + |
| 118 | + |
| 119 | + |
| 120 | + |
| 121 | + |
| 122 | + |
| 123 | + |
| 124 | + |
| 125 | + |
| 126 | +<img src="screenshots/ios-demoapp-slice.png" width="375px" height="196px" /> |
| 127 | + |
| 128 | +### Use when |
| 129 | +* you want full map styling capability to match the uses of your app (example: downplaying highways for a running app), |
| 130 | +* you want a platform independent map implementation, |
| 131 | +* you care about performance so you don't want a web based solution, |
| 132 | +* you want an open source map implementation that you can tweak yourself, |
| 133 | +* you want to leverage Mapbox's backend to visualize massive geo data sets, |
| 134 | +* you want advanced analytics about your app's users. |
| 135 | + |
| 136 | +## Prerequisites |
| 137 | +NativeScript 1.3.0 (`tns --version`) is required for smooth installation, so please upgrade if you need to. |
| 138 | + |
| 139 | +You need a Mapbox API access token (they have a free Starter plan!), so [sign up with Mapbox](https://www.mapbox.com/signup/). |
| 140 | +Once you've registered go to your Account > Apps > New token. The 'Default Secret Token' is what you'll need. |
| 141 | + |
| 142 | +## Installation |
| 143 | +From the command prompt go to your app's root folder and execute: |
| 144 | +``` |
| 145 | +tns plugin add nativescript-mapbox |
| 146 | +``` |
| 147 | + |
| 148 | +## Usage |
| 149 | + |
| 150 | +If you want a quickstart, [clone our demo app](https://github.com/EddyVerbruggen/nativescript-mapbox-demo). |
| 151 | +And here's the comprehensive list of supported functions: |
| 152 | + |
| 153 | +### function: show |
| 154 | +```js |
| 155 | + var mapbox = require("nativescript-mapbox"); |
| 156 | + |
| 157 | + mapbox.show({ |
| 158 | + accessToken: 'YOUR_API_ACCESS_TOKEN', // see 'Prerequisites' above |
| 159 | + style: 'emerald', // light|dark|emerald|satellite|streets , default 'streets' |
| 160 | + margins: { |
| 161 | + left: 40, // default 0 |
| 162 | + right: 40, // default 0 |
| 163 | + top: 450, // default 0 |
| 164 | + bottom: 40 // default 0 |
| 165 | + }, |
| 166 | + center: { // optional without a default |
| 167 | + lat: 52.3702160, |
| 168 | + lng: 4.8951680 |
| 169 | + }, |
| 170 | + zoomLevel: 9.25, // 0-20, default 0 |
| 171 | + showUserLocation: true, // default false - requires location permissions on Android which you can remove from AndroidManifest.xml if you don't need them |
| 172 | + hideAttribution: false, // default false, Mapbox requires this default if you're on a free plan |
| 173 | + hideLogo: false, // default false, Mapbox requires this default if you're on a free plan |
| 174 | + hideCompass: false, // default false |
| 175 | + disableRotation: false, // default false |
| 176 | + disableScroll: false, // default false |
| 177 | + disableZoom: false, // default false |
| 178 | + markers: [ // optional without a default |
| 179 | + { |
| 180 | + 'lat': 52.3732160, // mandatory |
| 181 | + 'lng': 4.8941680, // mandatory |
| 182 | + 'title': 'Nice location', // recommended to pass in |
| 183 | + 'subtitle': 'Really really nice location' // one line is available on iOS, multiple on Android |
| 184 | + } |
| 185 | + ] |
| 186 | + }).then( |
| 187 | + function(result) { |
| 188 | + console.log("Mapbox show done"); |
| 189 | + }, |
| 190 | + function(error) { |
| 191 | + console.log("mapbox show error: " + error); |
| 192 | + } |
| 193 | + ) |
| 194 | +``` |
| 195 | + |
| 196 | +### function: hide |
| 197 | +All further examples assume `mapbox` has been required. |
| 198 | +Also, all functions support promises, but we're leaving out the `.then()` stuff for brevity where it doesn't add value. |
| 199 | +```js |
| 200 | + mapbox.hide() |
| 201 | +``` |
| 202 | + |
| 203 | +### function: addMarkers |
| 204 | +```js |
| 205 | + mapbox.addMarkers([ |
| 206 | + { |
| 207 | + 'lat': 52.3602160, // mandatory |
| 208 | + 'lng': 4.8891680, // mandatory |
| 209 | + 'title': 'One-line title here', // no popup unless set |
| 210 | + 'subtitle': 'Infamous subtitle!' |
| 211 | + }, |
| 212 | + { |
| 213 | + .. |
| 214 | + } |
| 215 | + ]) |
| 216 | +``` |
| 217 | + |
| 218 | +### function: setCenter |
| 219 | +```js |
| 220 | + mapbox.setCenter( |
| 221 | + { |
| 222 | + lat: 52.3602160, // mandatory |
| 223 | + lng: 4.8891680, // mandatory |
| 224 | + animated: false // default true |
| 225 | + } |
| 226 | + ) |
| 227 | +``` |
| 228 | + |
| 229 | +### function: getCenter |
| 230 | +Here the promise callback makes sense, so adding it to the example: |
| 231 | +```js |
| 232 | + mapbox.getCenter().then( |
| 233 | + function(result) { |
| 234 | + console.log("Mapbox getCenter done, result: " + JSON.stringify(result)); |
| 235 | + }, |
| 236 | + function(error) { |
| 237 | + console.log("mapbox getCenter error: " + error); |
| 238 | + } |
| 239 | + ) |
| 240 | +``` |
| 241 | + |
| 242 | +### function: setZoomLevel |
| 243 | +```js |
| 244 | + mapbox.setZoomLevel( |
| 245 | + { |
| 246 | + level: 6.5, // mandatory, 0-20 |
| 247 | + animated: true // default true |
| 248 | + } |
| 249 | + ) |
| 250 | +``` |
| 251 | + |
| 252 | +### function: getZoomLevel |
| 253 | +```js |
| 254 | + mapbox.getZoomLevel().then( |
| 255 | + function(result) { |
| 256 | + console.log("Mapbox getZoomLevel done, result: " + JSON.stringify(result)); |
| 257 | + }, |
| 258 | + function(error) { |
| 259 | + console.log("mapbox getZoomLevel error: " + error); |
| 260 | + } |
| 261 | + ) |
| 262 | +``` |
| 263 | + |
| 264 | +### function: addPolygon |
| 265 | +Draw a shape (like a line/route, or star). Just connect the dots like we did as a child. The first person to tweet a snowman drawn with this function gets a T-shirt. |
| 266 | +```js |
| 267 | + // this is a boring triangle drawn near Amsterdam Central Station |
| 268 | + mapbox.addPolygon({ |
| 269 | + points: [ |
| 270 | + { |
| 271 | + 'lat': 52.3832160, // mandatory |
| 272 | + 'lng': 4.8991680 // mandatory |
| 273 | + }, |
| 274 | + { |
| 275 | + 'lat': 52.3632160, |
| 276 | + 'lng': 4.9011680 |
| 277 | + }, |
| 278 | + { |
| 279 | + 'lat': 52.3932160, |
| 280 | + 'lng': 4.8911680 |
| 281 | + } |
| 282 | + ] |
| 283 | + }) |
| 284 | +``` |
| 285 | + |
| 286 | +### function: hasFineLocationPermission / requestFineLocationPermission |
| 287 | +On Android 6 you need to request permission to be able to show the user's position on the map at runtime when targeting API level 23+. |
| 288 | +Even if the `uses-permission` tag for `ACCESS_FINE_LOCATION` is present in `AndroidManifest.xml`. |
| 289 | + |
| 290 | +Note that `hasFineLocationPermission` will return true when: |
| 291 | +* You're running this on iOS, or |
| 292 | +* You're targeting an API level lower than 23, or |
| 293 | +* You're using Android < 6, or |
| 294 | +* You've already granted permission. |
| 295 | + |
| 296 | +```js |
| 297 | + mapbox.hasFineLocationPermission().then( |
| 298 | + function(granted) { |
| 299 | + // if this is 'false' you probably want to call 'requestFineLocationPermission' now |
| 300 | + console.log("Has Location Permission? " + result); |
| 301 | + } |
| 302 | + ); |
| 303 | + |
| 304 | + // if no permission was granted previously this wil open a user consent screen |
| 305 | + mapbox.requestFineLocationPermission().then( |
| 306 | + function() { |
| 307 | + console.log("Location permission requested"); |
| 308 | + } |
| 309 | + ); |
| 310 | +``` |
| 311 | + |
| 312 | +Note that the `show` function will also check for permission if you passed in `showUserLocation : true`. |
| 313 | +If you didn't request permission before showing the map, and permission was needed, then |
| 314 | +the location is not drawn on the map and the plugin will log an error to the console. |
0 commit comments