Utilities.js 1.2 KB

123456789101112131415161718192021222324252627282930
  1. // @flow
  2. // Utility functions
  3. import { Platform } from 'react-native'
  4. import R from 'ramda'
  5. // useful cleaning functions
  6. const nullToEmpty = R.defaultTo('')
  7. const replaceEscapedCRLF = R.replace(/\\n/g)
  8. const nullifyNewlines = R.compose(replaceEscapedCRLF(' '), nullToEmpty)
  9. // Correct Map URIs
  10. export const locationURL = (address: string) => {
  11. let cleanAddress = nullifyNewlines(address)
  12. // https://developer.apple.com/library/ios/featuredarticles/iPhoneURLScheme_Reference/MapLinks/MapLinks.html
  13. let url = `http://maps.apple.com/?address=${cleanAddress}`
  14. // https://developers.google.com/maps/documentation/ios-sdk/urlscheme
  15. if (Platform.OS === 'android') url = `http://maps.google.com/?q=${cleanAddress}`
  16. return url
  17. }
  18. export const directionsURL = (address: string) => {
  19. let cleanAddress = nullifyNewlines(address)
  20. // https://developer.apple.com/library/ios/featuredarticles/iPhoneURLScheme_Reference/MapLinks/MapLinks.html
  21. let url = `http://maps.apple.com/?daddr=${cleanAddress}&dirflg=d`
  22. // https://developers.google.com/maps/documentation/ios-sdk/urlscheme
  23. if (Platform.OS === 'android') url = `http://maps.google.com/?daddr=${cleanAddress}`
  24. return url
  25. }