GoogleDirectionAndPlaceLibrary icon indicating copy to clipboard operation
GoogleDirectionAndPlaceLibrary copied to clipboard

Loop request to get place information

Open kimnamcham opened this issue 10 years ago • 0 comments

Your search near by library have a loop in request when get information. If you don't want get a place picture, i think must fix some line in code, because i had reached to over query limit google place api in 10 google place search. I had change some line to get only information (not include picture link of place):

private class RequestTask extends
        AsyncTask<String, Void, ArrayList<ContentValues>> {
    String status = "";
    Document doc = null;

    protected ArrayList<ContentValues> doInBackground(String... url) {
        try {
            HttpClient httpClient = new DefaultHttpClient();
            HttpContext localContext = new BasicHttpContext();
            HttpPost httpPost = new HttpPost(url[0]);
            HttpResponse response = httpClient.execute(httpPost,
                    localContext);
            InputStream in = response.getEntity().getContent();
            DocumentBuilder builder = DocumentBuilderFactory.newInstance()
                    .newDocumentBuilder();
            doc = builder.parse(in);
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ParserConfigurationException e) {
            e.printStackTrace();
        } catch (SAXException e) {
            e.printStackTrace();
        }

        if (doc != null) {
            status = getStatus(doc);

            if (status.equals(STATUS_OK)) {
                ArrayList<ContentValues> arr_cv = new ArrayList<ContentValues>();
                NodeList nl1 = doc.getElementsByTagName("result");
                for (int i = 0; i < nl1.getLength(); i++) {
                    ContentValues cv = new ContentValues();
                    Node node = nl1.item(i);
                    NodeList nl2 = node.getChildNodes();
                    node = nl2.item(getNodeIndex(nl2, "reference"));
                    cv.put("reference", node.getTextContent());

                    node = nl2.item(getNodeIndex(nl2, "name"));
                    cv.put(PLACE_NAME, node.getTextContent());

                    node = nl2.item(getNodeIndex(nl2, "vicinity"));
                    cv.put(PLACE_ADDRESS, node.getTextContent());

                    node = nl2.item(getNodeIndex(nl2, "icon"));
                    cv.put(PLACE_ICON, node.getTextContent());

                    node = nl2.item(getNodeIndex(nl2, "geometry"));
                    NodeList nl3 = node.getChildNodes();
                    Node nodechild = nl3.item(getNodeIndex(nl3, "location"));
                    NodeList nl4 = nodechild.getChildNodes();
                    nodechild = nl4.item(getNodeIndex(nl4, "lat"));
                    cv.put(PLACE_LATITUDE, nodechild.getTextContent());
                    nodechild = nl4.item(getNodeIndex(nl4, "lng"));
                    cv.put(PLACE_LONGITUDE, nodechild.getTextContent());

                    arr_cv.add(cv);
                }
                return arr_cv;
            }
            return null;
        }
        return null;
    }

kimnamcham avatar Mar 31 '15 02:03 kimnamcham