0

I am trying to fetch checkin locations from Google places API but I am getting error for XML FileNotFoundException when I try to read it through url.openStream(). My key is correct because I tried using it in some other URL in browser. If someone has used this feature then please let me know how to do this. Here is my code:

    public String checkingMessage()
    {
    String strURL = "https://maps.googleapis.com/maps/api/place/check-in/xml?sensor=true&key=" + GOOGLE_API_KEY;
    URL url;
    try 
    {
        url = new URL(strURL.replace(" ", "%20"));

        // Standard of reading a XML file
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        factory.setNamespaceAware(true);
        DocumentBuilder builder;
        Document doc = null;
        XPathExpression expr = null;
        builder = factory.newDocumentBuilder();

        doc = builder.parse(new InputSource(url.openStream()));

        // Create a XPathFactory
        XPathFactory xFactory = XPathFactory.newInstance();

        // Create a XPath object
        XPath xpath = xFactory.newXPath();

        // Compile the XPath expression
        expr = xpath.compile("//reference/text()");
        // Run the query and get a nodeset
        Object result = expr.evaluate(doc, XPathConstants.NODESET);
        NodeList nodes = (NodeList) result;

        String answer = nodes.item(0).getNodeValue();
        Toast.makeText(getApplicationContext(), answer, Toast.LENGTH_LONG);

    }catch(Exception ex){
        ex.printStackTrace();
    }
    return null;    
}

If I use direct url in browser, I get following error:

400: Your client has issued a malformed or illegal request. That’s all we know.

I dont know json parsing, so I am using XML. Output I believe should be like this, hence I am trying to fetch value of reference:

 <CheckInRequest>
   <reference>place_reference</reference>
 </CheckInRequest>

Update : I tried using HttpResponse and get response into Entity as follows

if (httpResponse.getStatusLine().getStatusCode() == 200){
    strResult = EntityUtils.toString(httpResponse.getEntity());
  }

But then I get MalFormedException on

doc = builder.parse(strResult); // doc is Document type

Either ways how can I get xml result into doc

Yogesh
  • 1,307
  • 3
  • 13
  • 18
  • I cant see where you are adding the place reference to your check-in request? I think you may have miss interoperated what a check-in is. As per the documentation: https://developers.google.com/maps/documentation/places/#PlaceCheckins A check-in requires a reference from a Place Search request, you can use it to indicate that a user has checked in to that Place. Check-in activity from your application is reflected in the Place search results that are returned - popular establishments are ranked more highly, making it easy for your users to find likely matches. – Chris Green May 01 '12 at 07:07

1 Answers1

0

I think you are trying to fetch check-in locations. I would like to do the same. But the check-in API seems to be POST-only at the moment, at least that's how I read the API documentation. Meaning your application can check-in, but you cannot query who checked in where (not even you yourself).

double-m
  • 118
  • 8