8.6 Converting a URL string to an AppLink ... decode vs encode

In 8.6 Converting a URL string to an AppLink I’m confused about encoding and decoding … The text says

  1. First, you need to decode the URL. URLs often include special characters in their paths, so you need to percent-encode the URL path. For example, you’d encode hello!world to hello%21world.

and the code says // 1
location = Uri.decodeFull(location ?? ‘’);

This is super confusing … or maybe something is wrong in either the text or the code. AT this point, are we trying to encode or decode?

@jefff9511 thanks and really appreciate your feedback. Definitely could improve the explanation here.

fromLocation takes a url string / path and decodes it. Typically with web url links, paths may have been encoded. Encoded string may look something like this:

%E4%B8%8A%E6%B5%B7%2B%E4%B8%AD%E5%9C%8B

This is especially useful for other languages, like Chinese. When you decode the string above it gives you this: 上海+中國

More example here:
URL Encoding  |  Google Maps Platform  |  Google Developers.

toLocation takes the current navigation state and generates an encoded url path.

Hope this helps!

1 Like