Search code examples
javaandroidunicodedriving-directions

Getting driving instructions in android application using Google Directions API


I have this android app where I am supposed to show the driving directions to the users. I am using Google Directions API for this. This involves making request to their url and getting the JSON in result. Now, the problem is : the driving directions are inside the TAG/Name - "html-instructions". Here I get the directions, but it's embedded with unicode characters for eg.

"html_instructions": "Take the 1st \u003cb\u003eleft\u003c/b\u003e toward \u003cb\u003eBannerugatta Rd\u003c/b\u003e"

How do I get rid of these unicode values and get the plain text out of it.

Please help


Solution

  • Try something like this:

    try {
        // Convert from Unicode to UTF-8
        String string = "abc\u5639\u563b";
        byte[] utf8 = string.getBytes("UTF-8");
    
        // Convert from UTF-8 to Unicode
        string = new String(utf8, "UTF-8");
    
    } catch (UnsupportedEncodingException e) {}