Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用地理编码API将google地图添加到java项目中?_Java - Fatal编程技术网

如何使用地理编码API将google地图添加到java项目中?

如何使用地理编码API将google地图添加到java项目中?,java,Java,我正在尝试将谷歌地图添加到我的框架中。但我有个错误。我的代码有什么错误,我做得对吗?如果我有一个地理编码API GoogleMaps,如何正确地执行它 public class GoogleMapsAdd { public static void main(String[] args) throws IOException { JFrame test = new JFrame("Google Maps"); try { Strin

我正在尝试将谷歌地图添加到我的框架中。但我有个错误。我的代码有什么错误,我做得对吗?如果我有一个地理编码API GoogleMaps,如何正确地执行它

public class GoogleMapsAdd {
    public static void main(String[] args) throws IOException {
        JFrame test = new JFrame("Google Maps");

        try {
            String imageUrl = "http://maps.google.com/staticmap?center=40,26&zoom=1&size=150x112&maptype=satellite&key=ABQIAAAAgb5KEVTm54vkPcAkU9xOvBR30EG5jFWfUzfYJTWEkWk2p04CHxTGDNV791-cU95kOnweeZ0SsURYSA&format=jpg";
            String destinationFile = "image.jpg";
            String str = destinationFile;
            URL url = new URL(imageUrl);
            InputStream is = url.openStream();
            OutputStream os = new FileOutputStream(destinationFile);

            byte[] b = new byte[2048];
            int length;

            while ((length = is.read(b)) != -1) {
                os.write(b, 0, length);
            }

            is.close();
            os.close();
        } catch (IOException e) {
            e.printStackTrace();
            System.exit(1);
        }

        test.add(new JLabel(new ImageIcon((new ImageIcon("image.jpg")).getImage().getScaledInstance(630, 600,
                java.awt.Image.SCALE_SMOOTH))));

        test.setVisible(true);
        test.pack();

    }
}

您可能正在ui线程上执行请求?如果我访问该URL,它只会返回一个带有消息的图像:“Staticmap API v1在2009年已被弃用,并在2016年1月被拒绝。应该使用Staticmap API v2。”因此,看起来您使用的代码来自一个过时的示例。您是对的,我不得不使用这个