|
| 1 | +<!DOCTYPE html> |
| 2 | +<html doctype=""> |
| 3 | +<head> |
| 4 | + <title>Demo SDK use</title> |
| 5 | + <script src="../bower_components/socket.io-client/socket.io.js"></script> |
| 6 | + <script src="bower_components/bringg-js-sdk/BringgSDK.js"></script> |
| 7 | + <script src="bower_components/jquery/dist/jquery.min.js"></script> |
| 8 | + <meta name="viewport" content="initial-scale=1.0"> |
| 9 | + <meta charset="utf-8"> |
| 10 | + <style> |
| 11 | + html, body { |
| 12 | + height: 100%; |
| 13 | + margin: 0; |
| 14 | + padding: 0; |
| 15 | + } |
| 16 | + #map { |
| 17 | + height: 100%; |
| 18 | + } |
| 19 | + </style> |
| 20 | + |
| 21 | + <script type="text/javascript"> |
| 22 | + var customer_access_token = null; |
| 23 | + var my_order_uuid = 'PLACE_A_SAMPLE_ORDER_UUID_HERE'; //note that this requires the 'UUID' attribute and not the 'ID'. |
| 24 | + |
| 25 | + function orderUpdateCb(order){ |
| 26 | + console.log('orderUpdateCb' + JSON.stringify(order)); |
| 27 | + // do something with order here |
| 28 | + } |
| 29 | + |
| 30 | + function locationUpdateCb(location){ |
| 31 | + console.log('locationUpdateCb'); |
| 32 | + if (location.lat() && location.lng() && map){ |
| 33 | + // do something with location here |
| 34 | + |
| 35 | + var center = new google.maps.LatLng(location.lat(), location.lng()); |
| 36 | + map.panTo(center); |
| 37 | + } |
| 38 | + } |
| 39 | + |
| 40 | + function etaUpdateCb(eta){ |
| 41 | + console.log('etaUpdateCb'); |
| 42 | + console.log(eta); |
| 43 | + // can do something with eta here |
| 44 | + } |
| 45 | + |
| 46 | + function onTaskRatedCb(){ |
| 47 | + console.log('onTaskRatedCb'); |
| 48 | + // task rated successfully! |
| 49 | + // we can call BringgSDK.disconnect() for example. |
| 50 | + } |
| 51 | + |
| 52 | + function onTaskEndedCb(){ |
| 53 | + console.log('onTaskEndedCb'); |
| 54 | + // task ended |
| 55 | + // we can call BringgSDK.disconnect() if we are not using a rating screen for example. |
| 56 | + } |
| 57 | + |
| 58 | + function onConnect(){ |
| 59 | + console.log('onConnect'); |
| 60 | + BringgSDK.watchOrder({ |
| 61 | + order_uuid: my_order_uuid |
| 62 | + }, function (result) { |
| 63 | + console.log('watch order result: ' + JSON.stringify(result)); |
| 64 | + if (result && result.shared_location) { |
| 65 | + console.log('calling init bringg with ' + result.share_uuid); |
| 66 | + BringgSDK.initializeBringg({share_uuid: result.share_uuid}, onBringgInitSuccess, onBringgInitFailed); |
| 67 | + } |
| 68 | + }); |
| 69 | +// alternatively here is an example for using share_uuid directly if you have it |
| 70 | +// BringgSDK.initializeBringg({share_uuid: PLACE_YOUR_SHARED_LOCATION_UUID_HERE}, onBringgInitSuccess, onBringgInitFailed); |
| 71 | + } |
| 72 | + |
| 73 | + function onBringgInitSuccess(configuration){ |
| 74 | + console.log('initializeBringg success'); |
| 75 | + console.log(configuration); |
| 76 | + |
| 77 | + // here we can do something with result.shared_location like storing it |
| 78 | + // in case we want to use the extra data later. |
| 79 | + } |
| 80 | + |
| 81 | + function onBringgInitFailed(error){ |
| 82 | + console.log('initializeBringg failed. error:' + error); |
| 83 | + } |
| 84 | + |
| 85 | + var map; |
| 86 | + function initMap() { |
| 87 | + map = new google.maps.Map(document.getElementById('map'), { |
| 88 | + center: {lat: -34.397, lng: 150.644}, |
| 89 | + zoom: 8 |
| 90 | + }); |
| 91 | + |
| 92 | + // beside |
| 93 | + BringgSDK.connect(customer_access_token, onConnect); |
| 94 | + |
| 95 | + // example for setting callbacks directly |
| 96 | + BringgSDK.setLocationUpdateCb(locationUpdateCb); |
| 97 | + BringgSDK.setETAUpdateCb(etaUpdateCb); |
| 98 | + BringgSDK.setOrderUpdateCb(orderUpdateCb); |
| 99 | + |
| 100 | + // example for setting callbacks implicitly |
| 101 | + BringgSDK.setEventCallback({ |
| 102 | + 'taskRatedCb': onTaskRatedCb, |
| 103 | + 'taskEndedCb': onTaskEndedCb |
| 104 | + }); |
| 105 | + } |
| 106 | + </script> |
| 107 | +</head> |
| 108 | +<body> |
| 109 | + <div id="map"></div> |
| 110 | + <!-- see https://developers.google.com/maps/documentation/javascript/get-api-key for obtaining maps api key--> |
| 111 | + <script src="https://maps.googleapis.com/maps/api/js?&key=YOUR_GOOGLE_MAPS_KEY_HERE&callback=initMap" async defer></script> |
| 112 | +</body> |
| 113 | +</html> |
0 commit comments