我正在使用 Foursquare API,我正在尝试获取附近的场地这是我正在使用的代码
public ArrayList<FsqVenue> SearchBykeyword(double latitude, double longitude, String query) throws Exception {
ArrayList<FsqVenue> venueList = new ArrayList<FsqVenue>();
try {
String ll = String.valueOf(latitude) + "," + String.valueOf(longitude);
URL url = new URL(API_URL + "/venues/search?ll=" + ll + "&query=" + query + "&radius=" + 50 + "&oauth_token=" + mAccessToken + "&v=20120610");
Log.d(TAG, "Opening URL " + url.toString());
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestMethod("GET");
urlConnection.setDoInput(true);
urlConnection.connect();
String response="";
try{
response = streamToString(urlConnection.getInputStream());
} catch (Exception e) {
String error= streamToString(urlConnection.getErrorStream());
Log.d("error", error);
throw e;
}
JSONObject jsonObj = (JSONObject) new JSONTokener(response).nextValue();
JSONArray groups = (JSONArray) jsonObj.getJSONObject("response").getJSONArray("groups");
int length = groups.length();
if (length > 0) {
for (int i = 0; i < length; i++) {
JSONObject group = (JSONObject) groups.get(i);
JSONArray items = (JSONArray) group.getJSONArray("items");
int ilength = items.length();
for (int j = 0; j < ilength; j++) {
JSONObject item = (JSONObject) items.get(j);
FsqVenue venue = new FsqVenue();
venue.id = item.getString("id");
venue.name = item.getString("name");
JSONObject location = (JSONObject) item.getJSONObject("location");
Location loc = new Location(LocationManager.GPS_PROVIDER);
loc.setLatitude(Double.valueOf(location.getString("lat")));
loc.setLongitude(Double.valueOf(location.getString("lng")));
venue.location = loc;
//venue.address = location.getString("address");
venue.distance = location.getInt("distance");
//venue.herenow = item.getJSONObject("hereNow").getInt("count");
venue.type = group.getString("type");
venueList.add(venue);
}
}
}
} catch (Exception ex) {
throw ex;
}
return venueList;
}
在这条线上:
urlConnection.setRequestMethod("GET");
我收到此错误:
07-08 22:45:16.432: W/System.err(27663): java.net.ProtocolException: Connection already established
07-08 22:45:16.432: W/System.err(27663): at java.net.HttpURLConnection.setRequestMethod(HttpURLConnection.java:654)
07-08 22:45:16.440: W/System.err(27663): at libcore.net.http.HttpsURLConnectionImpl.setRequestMethod(HttpsURLConnectionImpl.java:143)
07-08 22:45:16.440: W/System.err(27663): at com.android.guideme.FoursquareApp.SearchBykeyword(FoursquareApp.java:207)
07-08 22:45:16.447: W/System.err(27663): at com.android.guideme.GuideMeService$1.run(GuideMeService.java:89)
我不确定这意味着什么或有什么问题有什么想法?
提前致谢