Ejemplo n.º 1
0
 public void download() {
   InputStream in = null;
   CloseableHttpResponse res = null;
   while (true) {
     try {
       Center center = p.next();
       File file = new File(path + "\\" + center.getX() + "_" + center.getY() + ".png");
       file.createNewFile();
       HttpGet get = new HttpGet(centerToURL(center));
       System.out.println(get.getURI().toString());
       res = client.execute(get);
       in = res.getEntity().getContent();
       BufferedImage image = ImageIO.read(in);
       WriteImage(image, file);
     } catch (Exception e) {
       e.printStackTrace();
       break;
     } finally {
       try {
         in.close();
         res.close();
       } catch (Exception e) {
         e.printStackTrace();
       }
     }
     try {
       savePictureInfo();
     } catch (Exception e) {
       e.printStackTrace();
     }
   }
 }
Ejemplo n.º 2
0
  public Download(Center c1, Center c2) throws TooManyPictureException, IOException {
    p = new CenterProviter(c1, c2);

    this.mapInfo = new MapInfo(c1, c2);
    System.out.println("Hello");
    System.out.println(c2.getLat() + " " + c2.getLon());
    System.out.println(mapInfo);
    int pictureNumber = p.getMaxX() * p.getMaxY();
    if (pictureNumber > 150) {
      throw new TooManyPictureException("要下载" + pictureNumber + "个图片 这图片太多了");
    }
    client = HttpClients.createDefault();
  }
Ejemplo n.º 3
0
  /**
   * 将一个Center转化为URL
   *
   * <p>为了去除谷歌的水印 在获取图片的时候 请求的每张图片的HEIGHT将比设定的多60个像素
   *
   * @param c
   * @return
   */
  public static String centerToURL(Center c) {

    return baseURL
        + c.toString()
        + "&zoom="
        + Parameters.ZOOM
        + "&maptype=satellite"
        + "&size="
        + Parameters.WIDTH
        + "x"
        + (Parameters.HEIGHT + 60);
  }