Google Places API request Call
i've been struggeling with this all day now
I want to make an API call to Google Places but i can't seem to figure it out. I've tried this: http://blog.brianbuikema.com/2010/08/android-development-part-1-using-googles-places-api-to-develop-compelling-location-based-mobile-applications/
And now I have a string like this:
http://maps.google.com/maps/api/place/search/xml?location=40.717859,-73.9577937&开发者_C百科radius=1600&client=clientId&sensor=true_or_false&signature=SIGNATURE
Where I have the clientID as my client ID for the Places API on my gmail account and the signature filled by the UrlSinger's method signRequest
Now how do I get an XML or JSON object back?
Do I need to make a HttpRequest
or a HttpPost
(Or something completely different) ? I'm totally new to that.
I would love some example code.
Thanks in advance,
After another day of struggeling, I face-palmed myself.
Solution: Why would I need that signature?
A link like this works just fine:
https://maps.googleapis.com/maps/api/place/search/json?location=50.936364,5.873566&radius=500&name=ziekenhuis&sensor=false&key=FILL_IN_KEY_HERE
Retreiving the JSON object is being done by this method
private JSONObject executeHttpGet(String uri) throws Exception{
HttpGet req = new HttpGet(uri);
HttpClient client = new DefaultHttpClient();
HttpResponse resLogin = client.execute(req);
BufferedReader r = new BufferedReader(
new InputStreamReader(resLogin.getEntity()
.getContent()));
StringBuilder sb = new StringBuilder();
String s = null;
while ((s = r.readLine()) != null) {
sb.append(s);
}
Which I found here (At the bottom of the post):
http://blog.simonstahl.com/2011/03/16/login-with-oauth-to-the-foursquare-api-v2-from-android/
The method obviously needs some rewriting but it works.
精彩评论