Advertisement
Guest User

Untitled

a guest
Feb 19th, 2018
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. package unica.com;
  2.  
  3. import java.io.FileOutputStream;
  4. import java.io.IOException;
  5. import java.io.InputStream;
  6. import java.io.OutputStream;
  7. import java.net.URL;
  8. import javax.swing.ImageIcon;
  9. import javax.swing.JFrame;
  10. import javax.swing.JLabel;
  11.  
  12. public class Map210{
  13. public Map210(String title,String latitude, String longitude,int zoom, int width, int height, int scale, String type, String mark) {
  14.  
  15. JFrame map = new JFrame(title);
  16. map.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  17. map.setSize(width, height);
  18. map.setLocationRelativeTo(null);
  19. map.setVisible(true);
  20.  
  21. try {
  22.  
  23. String imageUrl = "https://maps.googleapis.com/maps/api/staticmap?center=";
  24. imageUrl+= latitude+ ","+ longitude+ "&zoom=" + zoom + "&size=" + width + "x" + height+"&scale="+zoom+"&maptype="+type+mark;
  25.  
  26. String destinationFile = "map210.jpg";
  27.  
  28. URL url = new URL(imageUrl);
  29. InputStream is = url.openStream();
  30. OutputStream os = new FileOutputStream(destinationFile);
  31. byte[] b = new byte[2048];
  32.  
  33. int length;
  34. while ((length = is.read(b)) != -1) {
  35. os.write(b, 0, length);
  36. }
  37. is.close();
  38. os.close();
  39. } catch (IOException e) {
  40. e.printStackTrace();
  41. System.exit(1);
  42. }
  43.  
  44. ImageIcon imageIcon = new ImageIcon((new ImageIcon("map210.jpg")).getImage().getScaledInstance(width, height,java.awt.Image.SCALE_SMOOTH));
  45. map.add(new JLabel(imageIcon));
  46. map.setVisible(true);
  47. map.pack();
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement