java - How can I pass a variable as a value in an API.. Im using Geocoding API. But i can't get the location -
double lat = 13.630754; double longi = 123.18484; jsonobjectrequest myrequest = new jsonobjectrequest( request.method.post, // here used variables latitude , longitude string.format(" https://maps.googleapis.com/maps/api/geocode/json?latlng=",lat,",",longi,"&key=my key"), new jsonobject(jsonparams), new response.listener<jsonobject>() { @override public void onresponse(jsonobject response) { toast.maketext(getapplicationcontext(),response.tostring(),toast.length_short).show(); // t.settext(response.tostring()); string address = null; try { address = response.getjsonarray("results").getjsonobject(0).getstring("formatted_address"); } catch (jsonexception e) { e.printstacktrace(); } t.settext(address); } },
string.format(" https://maps.googleapis.com/maps/api/geocode/json?latlng=",lat,",",longi,"&key=my key")
does not make sense.
either use string concatenation
"https://maps.googleapis.com/maps/api/geocode/json?latlng=" + lat + "," + longi + "&key=my key"
or proper format string
string.format("https://maps.googleapis.com/maps/api/geocode/json?latlng=%1$s,%2$s&key=my key", lat, longi )
see documentation: https://docs.oracle.com/javase/7/docs/api/java/util/formatter.html
wiki
Comments
Post a Comment