android - REQUEST_DENIED using Google Places API -
i developing application android using text search google places api. goal give address , latitude , longitude can mark on map. send following request google places :
using code :
public class geolocrdv { private latlng pos; private static final string api_key = " xxxxx_my_key "; private static final string places_text_search_url = "https://maps.googleapis.com/maps/api/place/textsearch/json?"; public geolocrdv(string rdvplace){ string url; try { url = places_text_search_url+"query=" + urlencoder.encode(rdvplace,"utf-8") + "&sensor=true&key=" + api_key; log.e("debug http", url); httpclient httpclient = new defaulthttpclient(); httpresponse response; response = httpclient.execute(new httpget(url)); statusline statusline = response.getstatusline(); if(statusline.getstatuscode() == httpstatus.sc_ok){ bytearrayoutputstream out = new bytearrayoutputstream(); response.getentity().writeto(out); out.close(); string responsestring = out.tostring(); log.e("debug resp", responsestring); jsonobject jsonobj = new jsonobject(responsestring); jsonarray results = (jsonarray) jsonobj.get("results"); log.e("debug json", results.tostring()); double rdvlat = (double) results.getjsonobject(0).getjsonobject("geometry").getjsonobject("location").get("lat"); log.e("debug json lat", float.tostring((float) rdvlat)); double rdvlng = (double) results.getjsonobject(0).getjsonobject("geometry").getjsonobject("location").get("lng"); log.e("debug json lng", float.tostring((float) rdvlng)); this.pos = new latlng(rdvlat, rdvlng); log.e("debug geo", pos.tostring()); }else{ response.getentity().getcontent().close(); } } catch (unsupportedencodingexception e1) { e1.printstacktrace(); } catch (clientprotocolexception e) { e.printstacktrace(); } catch (ioexception e) { e.printstacktrace(); } catch (jsonexception e) { e.printstacktrace(); } }
unfortunately response :
{ "html_attributions" : [], "results" : [], "status" : "request_denied" }
i tried :
- switch "sensor" parameter "true" , "false"
- change https http
- verify key correctly copied/pasted , corresponding 1 in manifest
- i went api console, services, clicked active services tab , verified 'places api' turned on. clicked on ? , "try out!" link next it. returned me same json (request_denied)
i read on stackoverflow try change port address 443 response places api, don't know how it.
finally, specify activated google places service after getting api key (because using maps api) , android key (not server or browser), not supposed issue since key works whole application.
i running out of ideas fix request problem, hope can me.
thanks in advance.
Comments
Post a Comment