Package com.frommap.ws.bean

Examples of com.frommap.ws.bean.Place


   * @param query Must be the category to search on a desired city
   * @param nextPageToken initially must be ""
   * @return the nextPageToken
   */
  public String placesSearchBy(String category, String andCity, String nextPageToken, List<Place> listOfPlaces) {
    Place p = new Place();
    JsonFactory factory = new JsonFactory();
    String type = category;
    String url = "https://maps.googleapis.com/maps/api/place/textsearch/";
    url += "json?query=" + category + "+in+" + andCity + "&sensor=false";
    url += "&key=" + _key;
   
    if (!nextPageToken.isEmpty()) {
      url += "&pagetoken=" + nextPageToken;
      nextPageToken = "";
    }
    try {
      JsonParser parser = factory.createJsonParser(new URL(url));
      // loop until token equal to "}"
      while (parser.nextToken() != JsonToken.END_OBJECT) {
        String fieldname = parser.getCurrentName();
        if ("html_attributions".equals(fieldname)) {
          parser.nextToken();
          while (parser.nextToken() != JsonToken.END_ARRAY) {
            parser.getText();
          }
        } else if ("next_page_token".equals(fieldname)) {
          nextPageToken = parser.getText();
        } else if ("results".equals(fieldname)) {
          JsonToken token = parser.nextToken();
          while ((token = parser.nextToken()) != JsonToken.END_ARRAY) {
            String resultToken = parser.getText();
            if (resultToken.equals("formatted_address")) {
              token = parser.nextToken();
              p.setAddr(parser.getText());
            } else if (resultToken.equals("lat")) {
              token = parser.nextToken();
              p.setLat(Double.parseDouble(parser.getText()));
            } else if (resultToken.equals("lng")) {
              token = parser.nextToken();
              p.setLng(Double.parseDouble(parser.getText()));
              token = parser.nextToken();
              token = parser.nextToken();
              resultToken = parser.getText();
            } else if (resultToken.equals("icon")) {
              token = parser.nextToken();
              String icon = parser.getText();
              p.setIcon(icon);
              type = icon.substring(icon.lastIndexOf("/")+1,icon.length()-7);
            } else if (resultToken.equals("name")) {
              token = parser.nextToken();
              p.setName(parser.getText());
            } else if (resultToken.equals("types")) {
              while((token = parser.nextToken()) != JsonToken.END_ARRAY) {
                if (token != JsonToken.START_ARRAY && token != JsonToken.END_ARRAY)
                  p.addTypes(parser.getText());
              }
            } else if (resultToken.equals("photos")) {
              while((token = parser.nextToken()) != JsonToken.END_ARRAY){
                resultToken = parser.getText();
                if ("html_attributions".equals(resultToken)) {
                  parser.nextToken();
                  while (parser.nextToken() != JsonToken.END_ARRAY) {
                    parser.getText();
                  }
                }
              }
            }
            if (p.getTypes() != null && token == JsonToken.END_OBJECT) {
              PlacesDao d = new PlacesDao(_url);
              p.setCategory(type);
              d.completeRecord(p);
              if(p.getId() == null)
                d.insertPlaces(p);
              Place b = new Place();
              b.setAddr(p.getAddr());
              b.setCategory(p.getCategory());
              b.setId(p.getId());
              b.setIcon(p.getIcon());
              b.setLat(p.getLat());
              b.setLng(p.getLng());
              b.setName(p.getName());
              b.setTypes(p.getTypes());
              listOfPlaces.add(b);
              p = new Place();
              d.close();
            }
          }
        }
        if ("status".equals(fieldname)) {
View Full Code Here


    }
    return nextPageToken;
  }

  public String nearbySearchBy(String type,double lat, double lng, String nextPageToken, List<Place> listOfPlaces) {
    Place p = new Place();
    JsonFactory factory = new JsonFactory();
    String category = type;
    String url = "https://maps.googleapis.com/maps/api/place/nearbysearch/";
    if (nextPageToken.isEmpty())
      url += "json?location=" + lat + "," + lng + "&types=" + type + "&radius=50000";
    else
      url += "json?pagetoken=" + nextPageToken;
    url += "&key=" + _key + "&sensor=false";
   
    try {
      JsonParser parser = factory.createJsonParser(new URL(url));
      // loop until token equal to "}"
      while (parser.nextToken() != JsonToken.END_OBJECT) {
        String fieldname = parser.getCurrentName();
        if ("html_attributions".equals(fieldname)) {
          parser.nextToken();
          while (parser.nextToken() != JsonToken.END_ARRAY) {
            parser.getText();
          }
        } else if ("next_page_token".equals(fieldname)) {
          nextPageToken = fieldname = parser.nextTextValue();
        } else if ("results".equals(fieldname)) {
          JsonToken token = parser.nextToken();
          while ((token = parser.nextToken()) != JsonToken.END_ARRAY) {
            String resultToken = parser.getText();
            if (resultToken.equals("lat") && p.getLat() == 0.0) {
              token = parser.nextToken();
              p.setLat(Double.parseDouble(parser.getText()));
            } else if (resultToken.equals("lng") && p.getLng() == 0.0) {
              token = parser.nextToken();
              p.setLng(Double.parseDouble(parser.getText()));
            } else if (resultToken.equals("icon")) {
              token = parser.nextToken();
              String icon = parser.getText();
              p.setIcon(icon);
              category = icon.substring(icon.lastIndexOf("/")+1,icon.length()-7);
            } else if (resultToken.equals("name")) {
              token = parser.nextToken();
              p.setName(parser.getText());
            } else if (resultToken.equals("types")) {
              while((token = parser.nextToken()) != JsonToken.END_ARRAY) {
                if (token != JsonToken.START_ARRAY && token != JsonToken.END_ARRAY)
                  p.addTypes(parser.getText());
              }
            } else if (resultToken.equals("photos")) {
              while((token = parser.nextToken()) != JsonToken.END_ARRAY){
                resultToken = parser.getText();
                if ("html_attributions".equals(resultToken)) {
                  parser.nextToken();
                  while (parser.nextToken() != JsonToken.END_ARRAY) {
                    parser.getText();
                  }
                }
              }
            } else if (resultToken.equals("vicinity")) {
              token = parser.nextToken();
              p.setAddr(parser.getText());
            }
            if (p.getTypes() != null && token == JsonToken.END_OBJECT) {
              PlacesDao d = new PlacesDao(_url);
              p.setCategory(category);
              d.completeRecord(p);
              if(p.getId() == null)
                d.insertPlaces(p);
              Place b = new Place();
              b.setAddr(p.getAddr());
              b.setCategory(p.getCategory());
              b.setId(p.getId());
              b.setIcon(p.getIcon());
              b.setLat(p.getLat());
              b.setLng(p.getLng());
              b.setName(p.getName());
              b.setTypes(p.getTypes());
              listOfPlaces.add(b);
              p = new Place();
              d.close();
            }
          }
        }
        if ("status".equals(fieldname)) {
View Full Code Here

        if (fieldname != null && fieldname.equals("HotelSummary")) {
          if (parser.nextToken() == JsonToken.START_ARRAY) {
            while(parser.nextToken() != JsonToken.END_ARRAY){
              fieldname = parser.getCurrentName();
              EanHotel hotel = new EanHotel();
              Place p = new Place();
              EanHotelDetail ean = new EanHotelDetail();
              p.setCategory("hotel");
              while(parser.nextToken() != JsonToken.END_OBJECT) {
                String str = fieldname = parser.getCurrentName();
               
                if (str != null) {
                  switch(str){
                  case "address1":
                    p.setAddr(getValue(parser));
                    break;
                  case "address2":
                    p.setAddr(p.getAddr() + " " + getValue(parser));
                    break;
                  case "highRate":
                    ean.setHightRate(Double.parseDouble(getValue(parser)));
                    break;
                  case "hotelRating":
                    ean.setHotelRating(Double.parseDouble(getValue(parser)));
                    break;
                  case "latitude":
                    p.setLat(Double.parseDouble(getValue(parser)));
                    break;
                  case "longitude":
                    p.setLng(Double.parseDouble(getValue(parser)));
                    break;
                  case "lowRate":
                    ean.setLowRate(Double.parseDouble(getValue(parser)));
                    break;
                  case "name":
                    p.setName(getValue(parser));
                    break;
                  case "postalCode":
                    ean.setPostalCode(getValue(parser));
                    break;
                  case "rateCurrencyCode":
                    ean.setRateCurrencyCode(getValue(parser));
                    break;
                  case "deepLink":
                    ean.setDeepLink(getValue(parser).replaceAll("(&amp;cid=)[^&]*(&amp;)","$1455207$2"));
                    break;
                  case "airportCode":
                    ean.setAirportCode(getValue(parser));
                    break;
                  case "shortDescription":
                    ean.setShortDescription(getValue(parser));
                    break;
                  }
                }
              }
              PlacesDao d = new PlacesDao(_url);
              d.completeRecord(p);
              UUID id = (p.getId() == null)? UUIDs.timeBased() : p.getId();
              d.insertPlaces(p, id);
              d.close();
              EanHotelDetailDao ed = new EanHotelDetailDao(_url);
              ean.setPlaceId(id);
              ed.insertRecord(ean);
View Full Code Here

TOP

Related Classes of com.frommap.ws.bean.Place

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.