aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes is it possible to display google maps in java swing application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "is it possible to display google maps in java swing application" Watch "is it possible to display google maps in java swing application" New topic
Author

is it possible to display google maps in java swing application

partha phukan
Ranch Hand

Joined: Mar 13, 2011
Posts: 31
hi everyone, i have been searching in google but still cannot find any solution to my problem. I need to display google maps in a JPanel. Is it possible? i have found somewhere using of jxmapviewer. but i didn't get the full idea. Can anyone help me to get out of it. Can anyone give me some link or some examples explaining how to display google maps in swing application.

Thanks in advance....
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42286
    
  64
See http://today.java.net/pub/a/today/2007/10/30/building-maps-into-swing-app-with-jxmapviewer.html for an example of using JXMapViewer. Not sure if it can be made to use Google Maps - the article only mentions NASA's Blue Marble satellite images and OpenStreetMap.


Ping & DNS - my free Android networking tools app
partha phukan
Ranch Hand

Joined: Mar 13, 2011
Posts: 31
Thanks for your reply. But it explains the use of NetBeans, but i am using Eclipse. I have gone through this early but i didn't get any idea. Would you please give me a better solution regarding this.

And what is the difference in using NASA's Blue Marble satellite images and OpenStreetMap and the JXMapViewer.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42286
    
  64
But it explains the use of NetBeans, but i am using Eclipse.

Those are IDEs; they have no bearing on the code you'd need to write.

I have gone through this early but i didn't get any idea. Would you please give me a better solution regarding this.

It would be hard to provide a better solution since we have no idea why this one isn't suitable. If you didn't understand an introductory article about technology X, then pointing you to an introductory article on technology Y isn't really a good problem-solving strategy. If you told us what you did or did not understand in that article, we might be able to help; I find it hard to believe that you didn't understand anything. I suggest to start by downloading the source code that comes with it, to study it, and to get it to run (note that you need to fiddle with the download URL because java.net is broken).

And what is the difference in using NASA's Blue Marble satellite images and OpenStreetMap and the JXMapViewer.

That article talks about JXMapViewer in detail; not sure what to add here that isn't discussed (and better so) in it. The web sites of both NASA Blue Marble and OpenStreetMap will tell you everything there is to know about those projects. They also both have Wikipedia pages if that's more to your liking.
partha phukan
Ranch Hand

Joined: Mar 13, 2011
Posts: 31
Thank you but i have a problem actually i did not find the source code for the program. If you can please give me the link for the source code..
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42286
    
  64
The link is in the article. It's broken, as I mentioned, but by looking at it it's pretty clear how to fix it.
partha phukan
Ranch Hand

Joined: Mar 13, 2011
Posts: 31
Sorry to say but i still cannot find any solution.I have downloaded the zip file and extracted it but it is not opening. i down load from http://projects.joshy.org/articles/MapApp/MapApp.zip.

Please give me some suggestion, so that i can continue.....
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42286
    
  64
Yes, that's the file. It extracts fine for me. It downloads pretty slowly, though, so make sure you're not trying to open it before it's fully downloaded. You could also try a different ZIP tool.
partha phukan
Ranch Hand

Joined: Mar 13, 2011
Posts: 31
but i tried and it is giving me error that "unable to launch the application".
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42286
    
  64
What are you doing when that message comes up? Which application are you using to extract the file? TellTheDetails.
Any standard ZIP tool (like WinZip) should work fine.
partha phukan
Ranch Hand

Joined: Mar 13, 2011
Posts: 31
First i extracted the zip file using WinRAR, after extracting i tried to run the master 'JNLP file ' first to observe how it performs. When i tried t run it shows me error "Unable to launch the application".

When i see the datails it shows two exceptions.

1. Exception

com.sun.deploy.net.FailedDownloadException: Unable to load resource: file:/F:/New Folder/MapApp/MapApp/${jnlp.codebase}/launch.jnlp
at com.sun.deploy.net.DownloadEngine.actionDownload(Unknown Source)
at com.sun.deploy.net.DownloadEngine.getCacheEntry(Unknown Source)
at com.sun.deploy.net.DownloadEngine.getCacheEntry(Unknown Source)
at com.sun.deploy.net.DownloadEngine.getResourceCacheEntry(Unknown Source)
at com.sun.deploy.net.DownloadEngine.getResourceCacheEntry(Unknown Source)
at com.sun.deploy.net.DownloadEngine.getResource(Unknown Source)
at com.sun.deploy.net.DownloadEngine.getResource(Unknown Source)
at com.sun.javaws.Launcher.updateFinalLaunchDesc(Unknown Source)
at com.sun.javaws.Launcher.prepareToLaunch(Unknown Source)
at com.sun.javaws.Launcher.prepareToLaunch(Unknown Source)
at com.sun.javaws.Launcher.launch(Unknown Source)
at com.sun.javaws.Main.launchApp(Unknown Source)
at com.sun.javaws.Main.continueInSecureThread(Unknown Source)
at com.sun.javaws.Main$1.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

2. Wrapped Exception
java.io.FileNotFoundException: F:\New Folder\MapApp\MapApp\${jnlp.codebase}\launch.jnlp (The system cannot find the path specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at sun.net.www.protocol.file.FileURLConnection.connect(Unknown Source)
at com.sun.deploy.net.BasicHttpRequest.doRequest(Unknown Source)
at com.sun.deploy.net.BasicHttpRequest.doRequest(Unknown Source)
at com.sun.deploy.net.BasicHttpRequest.doGetRequest(Unknown Source)
at com.sun.deploy.net.DownloadEngine.actionDownload(Unknown Source)
at com.sun.deploy.net.DownloadEngine.getCacheEntry(Unknown Source)
at com.sun.deploy.net.DownloadEngine.getCacheEntry(Unknown Source)
at com.sun.deploy.net.DownloadEngine.getResourceCacheEntry(Unknown Source)
at com.sun.deploy.net.DownloadEngine.getResourceCacheEntry(Unknown Source)
at com.sun.deploy.net.DownloadEngine.getResource(Unknown Source)
at com.sun.deploy.net.DownloadEngine.getResource(Unknown Source)
at com.sun.javaws.Launcher.updateFinalLaunchDesc(Unknown Source)
at com.sun.javaws.Launcher.prepareToLaunch(Unknown Source)
at com.sun.javaws.Launcher.prepareToLaunch(Unknown Source)
at com.sun.javaws.Launcher.launch(Unknown Source)
at com.sun.javaws.Main.launchApp(Unknown Source)
at com.sun.javaws.Main.continueInSecureThread(Unknown Source)
at com.sun.javaws.Main$1.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42286
    
  64
Right - that path is not valid until you fill in a value for "${jnlp.codebase}".

But why are you using the JNLP file at all? The README.txt file tells you how to run the application; it's downright trivial.
partha phukan
Ranch Hand

Joined: Mar 13, 2011
Posts: 31
Thank you i get some idea. But please guide me, i am facing problem in using "import org.jdesktop.application.Action" i mean to say that every org.jdesktop line is showing errors. i think the required jar file is not included in my project. i cannot able to include it. will you please again guide me. Thanks a lot.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42286
    
  64
The example app comes with various jar files containing org.jdesktop classes; be sure to add those to the classpath during compilation and runtime.
partha phukan
Ranch Hand

Joined: Mar 13, 2011
Posts: 31
Thank you once again for your guidance. Actually i am using java eclipse. Do i have to include something in my class path as i did for setting class path for jdk.

I have included all the jar files which is in dist folder of MapApp in a folder of my java project in eclipse. Again do i need to do something different.

Thank you.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42286
    
  64
This thread is by now straying far from the original topic. Questions about how to use Eclipse are best asked in the IDE forum.
partha phukan
Ranch Hand

Joined: Mar 13, 2011
Posts: 31
Sorry for my reply and question. Thanks for your guidance. i will try my best and will somehow manage. you have given me your valuable time and guided to this much. Ok. thank you once again. hope i can able to do it.
Ben Marco Philippe Palmejar
Greenhorn

Joined: Jul 24, 2013
Posts: 2
try this:

Main Form:

public class ImageRequest extends JFrame
{

public ImageRequest()
{

URL url_image = null;

try
{
url_image = new URL("http://maps.googleapis.com/maps/api/staticmap?center=New+York=16&size=600x300&maptype=roadmap&markers=color:blue%7Clabel:S%7C40.702147,-74.015794&markers=color:green%7Clabel:G%7C40.711614,-74.012318&markers=color:red%7Ccolor:red%7Clabel:C%7C40.718217,-73.998284&sensor=false");

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

ImageIcon imageIcon = new ImageIcon(url_image);

Container container = getContentPane();
container.setLayout(new BorderLayout());
container.add(new ImagePanel(imageIcon), BorderLayout.CENTER);

pack();

setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setLocationRelativeTo(null);
setVisible(true);

}

public static void main(String[] args)
{
new ImageRequest();
}

ImagePanel:

public class ImagePanel extends JPanel
{

private ImageIcon imageIcon;

public ImagePanel(ImageIcon imageIcon)
{
this.imageIcon = imageIcon;
}


@Override
public void paintComponent(Graphics g)
{
Graphics2D graphics2D = (Graphics2D) g;
graphics2D.drawImage(imageIcon.getImage(), 0, 0, null);
}

}
 
wood burning stoves
 
subject: is it possible to display google maps in java swing application