map.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import { AppleMaps, GoogleMaps } from 'expo-maps';
  2. import { Platform } from 'react-native';
  3. import { View } from 'app/design/view'
  4. import { BlockWrapper } from 'app/components/block-wrapper'
  5. // Requires development build (not Expo Go). Android: add apiKey to app.json android.config.googleMaps.apiKey
  6. export default function ElementMap({ data, height, blockWrapperProps }) {
  7. if (!data.location?.lat)
  8. return <></>
  9. const cameraPosition = {
  10. coordinates: { latitude: data.location.lat, longitude: data.location.lng },
  11. zoom: 14,
  12. };
  13. const mapStyle = { flex: 1 };
  14. if (Platform.OS === 'ios') {
  15. return (
  16. <BlockWrapper {...blockWrapperProps}>
  17. <View className='w-full aspect-square' style={{ height }}>
  18. <AppleMaps.View style={mapStyle} cameraPosition={cameraPosition} />
  19. </View>
  20. </BlockWrapper>
  21. );
  22. }
  23. if (Platform.OS === 'android') {
  24. return (
  25. <BlockWrapper {...blockWrapperProps}>
  26. <View className='w-full aspect-square' style={{ height }}>
  27. <GoogleMaps.View style={mapStyle} cameraPosition={cameraPosition} />
  28. </View>
  29. </BlockWrapper>
  30. );
  31. }
  32. return null;
  33. }