private void loadPointsFromServer(Location location) { try { String fetchUrl = Constants.kFindPOIUrl + "?latitude=" + location.getLatitude() + "&longitude=" + location.getLongitude() + "&radiusInMeters=1000"; URL url = new URL(fetchUrl); HttpURLConnection urlConnection = (HttpURLConnection) url .openConnection(); try { InputStream in = new BufferedInputStream( urlConnection.getInputStream()); BufferedReader r = new BufferedReader(new InputStreamReader(in)); StringBuilder stringBuilderResult = new StringBuilder(); String line; while ((line = r.readLine()) != null) { stringBuilderResult.append(line); } JSONArray jsonArray = new JSONArray( stringBuilderResult.toString()); for (int i = 0; i < jsonArray.length(); i++) { JSONObject jsonObject = jsonArray.getJSONObject(i); Double latitude = jsonObject.getDouble("Latitude"); Double longitude = jsonObject.getDouble("Longitude"); String description = jsonObject.getString("Description"); String itemUrl = jsonObject.getString("Url"); // The item URL comes back with quotes at the beginning, // so we strip them out itemUrl = itemUrl.replace("\"", ""); // Create a new geo point with this information and add it // to the overlay GeoPoint point = coordinatesToGeoPoint(new double[] { latitude, longitude }); OverlayItem overlayitem = new OverlayItem(point, description, itemUrl); mItemizedOverlay.addOverlay(overlayitem); } } catch (Exception ex) { Log.e("MainActivity", "Error getting data from server: " + ex.getMessage()); } finally { urlConnection.disconnect(); } } catch (Exception ex) { Log.e("MainActivity", "Error creating connection: " + ex.getMessage()); } }