android - Google Places API returning provided API key is invalid -


read thru posts on subject , tried out combination : 1. used android key while making google places api call ( 2. switched browser key 3. later tried server key. 4. re-generated keys , tried combination 1-3.

nothing working !!. key mapv2 api in manifest file android key. app working correctly until created new project , listed package new project. recreated new android key package. old key still there different project. have not deleted old project removed key under it. have new keys android, browser under new project. doing wrong?.

i error message " provided api key invalid"... when make call browser using browser key working . not not android app . tips ?.

please see code below:-

final string places_api_base = "https://maps.googleapis.com/maps/api/place/nearbysearch"; final string out_json = "/json"; final string key=<browser-key> final string sensor="false"; stringbuilder querystring = new stringbuilder(places_api_base+out_json); try{ querystring.append("?sensor="+sensor+"&key="+key); string localquery="&location=37.316318,-122.005916&radius=500&name=traderjoe";                 querystring.append(urlencoder.encode(localquery, "utf-8"));                 url url = new url(querystring.tostring());                  httpurlconnection connection = (httpurlconnection)url.openconnection();          connection.setrequestmethod("get");            string line;    stringbuilder builder = new stringbuilder();    bufferedreader reader = new bufferedreader(      new inputstreamreader(connection.getinputstream()));    while((line = reader.readline()) != null) {     builder.append(line); }        system.out.println("json builder input google places query="+builder.tostring()); 

this error message:- provided api key invaild

here code googleplaceapi in csharp

public list<googleplace> googleapiplace(coordinate startcoordinate)     {         list<googleplace> listofplace = new list<googleplace> ();          string apiurl = "https://maps.googleapis.com/maps/api/place/nearbysearch/xml?location=";         string apikey = "mykey";          string linkapi = apiurl + startcoordinate.latitude.tostring ().replace (',', '.') + "," + startcoordinate.longitude.tostring ().replace (',', '.') + "&radius=1000&sensor=true&types=establishment&key=" + apikey;          var request = httpwebrequest.create(linkapi);         request.contenttype = "application/xml";         request.method = "get";          try         {             using (httpwebresponse response = request.getresponse() httpwebresponse)             {                 if (response.statuscode != httpstatuscode.ok)                 {                     console.out.writeline("error fetching data, server returned status code {0}", response.statuscode);                 }                 using (streamreader reader = new streamreader(response.getresponsestream()))                 {                     var content = reader.readtoend();                     if (string.isnullorwhitespace(content))                     {                         console.out.writeline("responsed contained empty body...");                     }                     else                     {                         xmldocument document = new xmldocument();                         document.loadxml(content);                         console.out.writeline(content);                         xmlnodelist nodelist = document.getelementsbytagname("result");                          foreach (xmlnode docnode in nodelist)                         {                             string tot = ((xmlelement)docnode).getelementsbytagname("lat")[0].innertext;                             googleplace place = new googleplace()                             {                                 location = new location()                                 {                                     coordinate = new coordinate()                                     {                                         latitude = double.parse(((xmlelement)docnode).getelementsbytagname("lat")[0].innertext, cultureinfo.invariantculture),                                         longitude = double.parse(((xmlelement)docnode).getelementsbytagname("lng")[0].innertext, cultureinfo.invariantculture)                                     }                                 },                                 name = docnode.childnodes.item(0).innertext.trimend().trimstart(),                                 vicinity = docnode.childnodes.item(1).innertext.trimend().trimstart()                             };                             listofplace.add(place);                         }                     }                 }             }         }         catch         {             //todo : exception         }          return listofplace;     } 

the api key here enter image description here

hope can ;)


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -