|
| 1 | +/* |
| 2 | +Copyright 2022 Adobe. All rights reserved. |
| 3 | +This file is licensed to you under the Apache License, Version 2.0 (the "License"); |
| 4 | +you may not use this file except in compliance with the License. You may obtain a copy |
| 5 | +of the License at http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | +
|
| 7 | +Unless required by applicable law or agreed to in writing, software distributed under |
| 8 | +the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS |
| 9 | +OF ANY KIND, either express or implied. See the License for the specific language |
| 10 | +governing permissions and limitations under the License. |
| 11 | +*/ |
| 12 | + |
| 13 | +import React from 'react'; |
| 14 | +import {Button, ScrollView, Text, View} from 'react-native'; |
| 15 | +import { |
| 16 | + Places, |
| 17 | + PlacesAuthStatus, |
| 18 | + PlacesGeofence, |
| 19 | + PlacesGeofenceTransitionType, |
| 20 | + PlacesLocation, |
| 21 | +} from '@adobe/react-native-aepplaces'; |
| 22 | +import {NavigationProps} from '../types/props'; |
| 23 | +import styles from '../styles/styles'; |
| 24 | + |
| 25 | +const EXAMPLE_LATITUDE = 37.3325958; |
| 26 | +const EXAMPLE_LONGITUDE = -121.8910217; |
| 27 | +const EXAMPLE_GEOFENCE_ID = '82e2eb52-e925-41a3-9d50-418a2e015608'; |
| 28 | +const EXAMPLE_RADIUS = 50; |
| 29 | + |
| 30 | +const extensionVersion = async () => { |
| 31 | + const version = await Places.extensionVersion(); |
| 32 | + console.log('AdobeExperienceSDK: Places version: ' + version); |
| 33 | +}; |
| 34 | + |
| 35 | +const getNearbyPointsOfInterest = async () => { |
| 36 | + const location = new PlacesLocation(EXAMPLE_LONGITUDE, EXAMPLE_LATITUDE); |
| 37 | + try { |
| 38 | + const pois = await Places.getNearbyPointsOfInterest(location, 2); |
| 39 | + console.log( |
| 40 | + `AdobeExperienceSDK: Places pois: ${pois[0]?.['name'] || '[]'}`, |
| 41 | + ); |
| 42 | + } catch (e) { |
| 43 | + console.log(`AdobeExperienceSDK: Places error: ${e}`); |
| 44 | + } |
| 45 | +}; |
| 46 | + |
| 47 | +const processGeofence = () => { |
| 48 | + const geofence = new PlacesGeofence( |
| 49 | + EXAMPLE_GEOFENCE_ID, |
| 50 | + EXAMPLE_LATITUDE, |
| 51 | + EXAMPLE_LONGITUDE, |
| 52 | + EXAMPLE_RADIUS, |
| 53 | + 10, |
| 54 | + ); |
| 55 | + Places.processGeofence(geofence, PlacesGeofenceTransitionType.EXIT); |
| 56 | + console.log('Geofence processed'); |
| 57 | +}; |
| 58 | + |
| 59 | +const getCurrentPointsOfInterest = async () => { |
| 60 | + const pois = await Places.getCurrentPointsOfInterest(); |
| 61 | + console.log(`AdobeExperienceSDK: Places pois: ${pois[0]?.['name'] || '[]'}`); |
| 62 | +}; |
| 63 | + |
| 64 | +const getLastKnownLocation = async () => { |
| 65 | + const location = await Places.getLastKnownLocation(); |
| 66 | + console.log( |
| 67 | + `AdobeExperienceSDK: Places location: ${JSON.stringify(location)}`, |
| 68 | + ); |
| 69 | +}; |
| 70 | + |
| 71 | +const clear = () => { |
| 72 | + Places.clear(); |
| 73 | + console.log('cleared'); |
| 74 | +}; |
| 75 | + |
| 76 | +const setAuthorizationStatus = () => { |
| 77 | + Places.setAuthorizationStatus(PlacesAuthStatus.ALWAYS); |
| 78 | + console.log('Authorization status set'); |
| 79 | +}; |
| 80 | + |
| 81 | +const PlacesView = ({navigation: {goBack}}: NavigationProps) => { |
| 82 | + return ( |
| 83 | + <View style={styles.container}> |
| 84 | + <ScrollView contentContainerStyle={{marginTop: 75}}> |
| 85 | + <Button onPress={goBack} title="Go to main page" /> |
| 86 | + <Text style={styles.welcome}>Places</Text> |
| 87 | + <Button title="extensionVersion()" onPress={extensionVersion} /> |
| 88 | + <Button |
| 89 | + title="getNearbyPointsOfInterest()" |
| 90 | + onPress={getNearbyPointsOfInterest} |
| 91 | + /> |
| 92 | + <Button title="processGeofence()" onPress={processGeofence} /> |
| 93 | + <Button |
| 94 | + title="getCurrentPointsOfInterest()" |
| 95 | + onPress={getCurrentPointsOfInterest} |
| 96 | + /> |
| 97 | + <Button title="getLastKnownLocation()" onPress={getLastKnownLocation} /> |
| 98 | + <Button |
| 99 | + title="setAuthorizationStatus()" |
| 100 | + onPress={setAuthorizationStatus} |
| 101 | + /> |
| 102 | + <Button title="clear" onPress={clear} /> |
| 103 | + </ScrollView> |
| 104 | + </View> |
| 105 | + ); |
| 106 | +}; |
| 107 | + |
| 108 | +export default PlacesView; |
0 commit comments