Home > front end >  Unable to open URL: maps:0,0?q=XX,XX
Unable to open URL: maps:0,0?q=XX,XX

Time:01-03

I got a lot of these errors in production: "Unable to open URL: maps:0,0?q=XX,XX". All are from iOS v16.x, on different devices. My links are created this way:


const MapLink = ({ coords, label, style, type = 'tDF' }: Props) => {
  const { theme } = useTheme();

  const [can, setCan] = useState<boolean>();

  const url = useMemo(
    () =>
      coords
        ? `${Platform.select({
            ios: 'maps',
            android: 'geo',
          })}:0,0?q=${coords.latitude},${coords.longitude}`
        : '',
    [coords],
  );

  useEffect(() => {
    coords
      ? Linking.canOpenURL(url)
          .then(r => setCan(r))
          .catch(() => setCan(false))
      : setCan(false);
  }, [coords]);

  return can && coords && coords.latitude && coords.longitude ? (
    <Button
      bgColor={theme.color.textL}
      type={'underline'}
      size={'sm'}
      label={label ?? ''}
      onPress={() => Linking.openURL(url).then()}
      style={style}
    />
  ) : label ? (
    <Typo type={type} text={label} color={theme.color.text} />
  ) : null;
};

I can't reproduce it neither on Simulator, neither on a real device. Before activate the link, I check with canOpenURL, so I don't understand how it's possibile that 1) A simple map link is not openable 2) canOpenURL should return true to activate the link, so why the error then?

CodePudding user response:

Try this:

<View>
  {
    can && coords && coords.latitude && coords.longitude ? (
  <Button
  bgColor={theme.color.textL}
  type={'underline'}
  size={'sm'}
  label={label ?? ''}
  onPress={() => Linking.openURL(url).then()}
  style={style}
/>
  ) :label ? (
<Typo type={type} text={label} color={theme.color.text} />
) :null
}

</View>
  • Related