|
| 1 | +--- |
| 2 | +title: Location capabilities in Adaptive Card Extension |
| 3 | +description: Geolocation is a new action that the SharePoint Adaptive Card Extension framework supports, which enables third party developers to come up with their ___location specific scenarios. |
| 4 | +ms.date: 04/06/2022 |
| 5 | +ms.prod: sharepoint |
| 6 | +ms.localizationpriority: high |
| 7 | +--- |
| 8 | +# Location capabilities in Adaptive Card Extension |
| 9 | + |
| 10 | +> [!NOTE] |
| 11 | +> The geolocation capability in Adaptive Card Extension will be available in SPFx v1.15. |
| 12 | +> |
| 13 | +> So make sure that you have installed it before proceeding further. |
| 14 | +> |
| 15 | +> For more information on installing the SPFx v1.15 Preview, see [SharePoint Framework v1.15 release notes](../../../../release-1.15.md). |
| 16 | +> |
| 17 | +> This tutorial also assumes that you have already built a SharePoint Adaptive Card Extension. |
| 18 | +> |
| 19 | +> To learn how to create your first SharePoint Adaptive Card Extension, try out [this tutorial](../../../get-started/build-first-sharepoint-adaptive-card-extension.md). |
| 20 | +
|
| 21 | +### New action types for geolocation |
| 22 | + |
| 23 | +There are 2 Location actions: |
| 24 | + |
| 25 | +1. Get Location |
| 26 | +1. Show Location |
| 27 | + |
| 28 | +### Get Location: |
| 29 | + |
| 30 | +Gives user’s current device ___location or opens a ___location picker and returns the ___location chosen by the user. In the browser it uses Bing Maps as the mapping interface. |
| 31 | + |
| 32 | +The ACE action for Get Location is: `VivaAction.GetLocation`. |
| 33 | + |
| 34 | +It takes an optional boolean parameter: `ChooseLocationOnMap`. |
| 35 | + |
| 36 | +If the property `ChooseLocationOnMap` is set to `true`, then the action will open a map, and user will get to choose a ___location on the map, otherwise, it will fetch user's current device ___location. |
| 37 | + |
| 38 | +### Show Location: |
| 39 | + |
| 40 | +With this action, a map shows up on the screen on which you can either show the user's current ___location on the map or you can show your specified coordinates on the map. |
| 41 | + |
| 42 | +The ACE action for Show Location is: `VivaAction.ShowLocation`. |
| 43 | + |
| 44 | +It takes an optional ___location parameter: `locationCoordinates`. |
| 45 | + |
| 46 | +To show a specific ___location, you should pass the ___location coordinates (latitude and longitude) via the `locationCoordinates` parameter. |
| 47 | + |
| 48 | +The `locationCoordinates` object consists of the following properties: |
| 49 | + |
| 50 | +```typescript |
| 51 | +{ |
| 52 | + /** |
| 53 | + * Latitude of the ___location. |
| 54 | + */ |
| 55 | + latitude: number; |
| 56 | + |
| 57 | + /** |
| 58 | + * Longitude of the ___location. |
| 59 | + */ |
| 60 | + longitude: number; |
| 61 | + |
| 62 | + /** |
| 63 | + * Timestamp (optional). |
| 64 | + */ |
| 65 | + timestamp?: number; |
| 66 | + |
| 67 | + /** |
| 68 | + * Accuracy of the ___location (optional). |
| 69 | + */ |
| 70 | + accuracy?: number; |
| 71 | +} |
| 72 | +``` |
| 73 | + |
| 74 | +### Tutorial and Examples |
| 75 | + |
| 76 | +You can take a look at [this tutorial](./GeolocationTutorial.md) which goes over the step by step details of how you could create a card with geolocation actions. |
| 77 | + |
| 78 | +The following examples describe the geolocation action and their purpose. |
| 79 | + |
| 80 | +1. **Get user's current ___location** |
| 81 | + |
| 82 | + In your template JSON, introduce the following action: |
| 83 | + |
| 84 | + ```json |
| 85 | + "actions": [{ |
| 86 | + type: 'VivaAction.GetLocation', |
| 87 | + id: 'Get Location' |
| 88 | + }] |
| 89 | + ``` |
| 90 | + |
| 91 | + When this action gets invoked, user's current geolocation is fetched and is passed to the Third Party Developer via the onAction callback. |
| 92 | + |
| 93 | + > [!NOTE] |
| 94 | + > In this case, map doesn't show up. |
| 95 | + |
| 96 | +1. **Select ___location from a map** |
| 97 | + |
| 98 | + In your template JSON, introduce the following action: |
| 99 | + |
| 100 | + ```json |
| 101 | + "actions": [{ |
| 102 | + type: 'VivaAction.GetLocation', |
| 103 | + id: 'Get Location', |
| 104 | + parameters: {chooseLocationOnMap: true} |
| 105 | + }] |
| 106 | + ``` |
| 107 | + |
| 108 | + When this action gets invoked, a map pointing to user's current ___location opens up and the user gets to select and share the ___location of their choice. The selected ___location's coordinates are passed to the Third Party Developer via the onAction callback. |
| 109 | + |
| 110 | +1. **Display user's current ___location** |
| 111 | + |
| 112 | + In your template JSON, introduce the following action: |
| 113 | + |
| 114 | + ```json |
| 115 | + "actions": [{ |
| 116 | + type: 'VivaAction.ShowLocation', |
| 117 | + id: 'Show Location' |
| 118 | + }] |
| 119 | + ``` |
| 120 | + |
| 121 | + When this action gets invoked, a map opens up and the user's current ___location coordinates are shown on it. |
| 122 | + |
| 123 | +1. **Display a specified ___location** |
| 124 | + |
| 125 | + In your template JSON, introduce the following action: |
| 126 | + |
| 127 | + ```json |
| 128 | + "actions": [{ |
| 129 | + type: 'VivaAction.ShowLocation', |
| 130 | + id: 'Show Location', |
| 131 | + parameters: { |
| 132 | + locationCoordinates: { |
| 133 | + latitude: 28.6132039578389, |
| 134 | + longitude: 77.229488240066 |
| 135 | + } |
| 136 | + } |
| 137 | + }] |
| 138 | + ``` |
| 139 | + |
| 140 | + When this action gets invoked, a map opens up and it shows the ___location coordinates specified in the action. |
| 141 | + |
| 142 | +### Access geolocation actions via card-designer card's property pane |
| 143 | + |
| 144 | +If you don't want to write code, but still wish to see how the geolocation actions work, then you can explore [this tutorial](./GeolocationPropertyPane.md) which lets you create cards with geolocation actions via property pane. |
| 145 | + |
| 146 | +> [!NOTE] |
| 147 | +> Theses geolocation actions can be added on the card view or the buttons of the card view or inside the quick view. |
| 148 | + |
| 149 | +### Permission and error codes |
| 150 | + |
| 151 | +For the ___location APIs to work, the user has to grant the permission to access device's ___location. |
| 152 | + |
| 153 | + |
| 154 | +Error Code | Error Description |
| 155 | +----------------- | ----------------- |
| 156 | +PermissionDenied | User has denied the permission to access ___location |
| 157 | +InternalError | An unexpected error happened while invoking the ___location APIs |
| 158 | +HostNotSupported | The ___location action is being used in an unsupported environment |
| 159 | + |
| 160 | + |
| 161 | +### Callbacks for Card Developers |
| 162 | + |
| 163 | +When the action `VivaAction.GetLocation` is invoked, we pass the fetched ___location coordinates via the onAction callback. |
| 164 | + |
| 165 | +> [!NOTE] |
| 166 | +> onAction callback is not invoked for `VivaAction.ShowLocation`. |
| 167 | + |
| 168 | +For actions: `VivaAction.GetLocation` and `VivaAction.ShowLocation`, if the user lands into an error state, then an onError callback will get invoked, to which we pass the action name and the error code. |
| 169 | + |
| 170 | +### Availability of geolocation actions |
| 171 | + |
| 172 | +> [!NOTE] |
| 173 | +> These new actions are **only available in the browser** currently. Viva Connections desktop and Viva Connections mobile support will be enabled later. |
| 174 | +After General Availability the support matrix for actions will look like: |
| 175 | + |
| 176 | +Action | Viva Connection Desktop | Viva Connections Mobile | Browser |
| 177 | +------------- | ------------- | ------------- | ------------- |
| 178 | +Get Location | Not Supported | Supported | Supported |
| 179 | +Show Location | Not Supported | Supported | Supported |
0 commit comments