Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parsing "html_attributions" from Google Places response in JAVA

Per policy it is mandatory show "html_attributions" in the app. This response is received as - "html_attributions" : [ "Listings by \u003ca href=\"http:// Some website.com/\"\u003esSome website\u003c/a\u003e" ]

When I parse it as jObject.getJSONArray("html_attributions") I get - ["Listings by <a href=\"http:\/\/www.some website.com\/\">some website<\/a>"]

This cannot be displayed as is since it is not html correct. Is there any method to parse this attribution correctly so that html valid string is extracted?

like image 358
user1930106 Avatar asked Jul 09 '14 06:07

user1930106


People also ask

How do I get my address from Google Places API?

Getting startedGo to the Google Cloud Console. Click the Select a project button, then select the same project you set up for the Maps JavaScript API and click Open. From the list of APIs on the Dashboard, look for Places API. If you see the API in the list, you're all set.

How do I get more than 5 reviews on Google Places API?

Save this answer. Show activity on this post. In order to have access to more than 5 reviews with the Google API you have to purchase Premium data Access from Google. That premium plan will grant you access to all sorts of additional data points you have to shell out a pretty penny.

Can you store Google Places API data?

Note that the place ID, used to uniquely identify a place, is exempt from the caching restriction. You can therefore store place ID values indefinitely.


1 Answers

Go through this Google Places Api Sample which describes a way of doing so.

It has a method formatPlaceDetails that Format details of the place for display. It does not support HTML tags directly, they need to be encoded first.

private static Spanned formatPlaceDetails(Resources res, CharSequence name, String id,
            CharSequence address, CharSequence phoneNumber, Uri websiteUri) {
        Log.e(TAG, res.getString(R.string.place_details, name, id, address, phoneNumber,
                websiteUri));
        return Html.fromHtml(res.getString(R.string.place_details, name, id, address, phoneNumber,
                websiteUri));

    }

string.xml

<string name="place_details">&lt;b&gt;%1$s&lt;/b&gt;&lt;br/&gt;&lt;i&gt;Place Id: %2$s&lt;/i&gt;&lt;br/&gt;Address: %3$s&lt;br/&gt;Phone: %4$s&lt;br/&gt;Website: %5$s</string>
like image 55
Vipul Asri Avatar answered Nov 07 '22 10:11

Vipul Asri