how to use google map server with JXMapKit

View: New views
17 Messages — Rating Filter:   Alert me  

how to use google map server with JXMapKit

by jdnc-interest :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi all;

i tried to use this code in my application to show google map;


import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import javax.swing.*;
import javax.swing.event.*;
import org.jdesktop.swingx.*;
import org.jdesktop.swingx.mapviewer.*;

public class GoogleMapTest
   {
    public static JXMapKit jxMapKit;

    public static void main(String args[])
       throws Exception
       {
         
         // Get us a map provider to get Google maps.
         
         GoogleMapsProvider map = new GoogleMapsProvider();

         // From here, set things up to get the main map viewer using this provider as a source.
         
         TileFactoryInfo tileProviderInfo = map.getTileProviderInfo();
         TileFactory tileFactory = new DefaultTileFactory (tileProviderInfo);
         jxMapKit = new JXMapKit();
         
         // Create a frame for the application and set up the window appropriately.
         
         JFrame frame = new JFrame("Google Maps Test");        
         frame.getContentPane().add(jxMapKit);
         frame.setSize(800, 600);
         frame.setVisible(true);

         // Set up the map viewer, and give a location and zoom level for something familiar.
         
         jxMapKit.setTileFactory(tileFactory);
         jxMapKit.setCenterPosition(new GeoPosition(43.005, -81.275));
         jxMapKit.setZoom(3);

         // Add a sample waypoint.
         
         WaypointPainter waypointPainter = new WaypointPainter();
         waypointPainter.setRenderer(new WaypointRenderer() {
            public boolean paintWaypoint(Graphics2D g, JXMapViewer map, Waypoint wp) {
                g.setColor(Color.RED);
                g.fillRect(-5,-5,10,10);
                g.setColor(Color.BLACK);
                g.drawRect(-5,-5,10,10);
                return true;
            }
         });
   
         waypointPainter.getWaypoints().add(new Waypoint(43.005, -81.275));
         jxMapKit.getMainMap().setOverlayPainter(waypointPainter);        

         // Add a mouse listener to check for the waypoint being clicked.
         
         jxMapKit.getMainMap().addMouseListener(new MouseInputAdapter() {
            public void mouseClicked(MouseEvent e) {
               
                // Get the screen point of mouse click.
                Point pt = e.getPoint();

                // Get the pixel coordinates of the waypoint in question from the map.
               
                JXMapViewer map = jxMapKit.getMainMap();
                Point2D point = map.getTileFactory().geoToPixel(new GeoPosition(43.005, -81.275), map.getZoom());

                // Adjust the pixel coordinates to their relative position on screen.
               
                Rectangle bounds = map.getViewportBounds();
                int x = (int)(point.getX() - bounds.getX());
                int y = (int)(point.getY() - bounds.getY());

                // Create a bounding rectangle around the waypoint, and see if the mouse click occured
                // within its boundaries.
               
                Rectangle rect = new Rectangle(x - 5, y - 5, 10, 10);
                if (rect.contains(pt)) {
                    JFrame newframe = new JFrame("Waypoint");
                    JLabel newlabel = new JLabel("Waypoint at (43.005, -81.275)");
                    newframe.getContentPane().add(newlabel);
                    newframe.pack();
                    newframe.setVisible(true);
                }
 
            }
        });

         
         // Add listener to kill the things if the window dies.
         
         frame.addWindowListener(new WindowAdapter() {
             public void windowClosing(WindowEvent e) {
               System.exit(0);
             }
          });

         // Wait around for a while here.
         
         while (frame.isVisible())
           {
             Thread.sleep(200);
           }
       }
   }

am using netbeans6 and i installed the swing-sw with the JXMapKit, however,
GoogleMapsProvider map = new GoogleMapsProvider(); is not recognizable by the compiler. i don't know do i have to install another API for google??

if so please tell me the name of the API
[Message sent by forum member 'crjava' (crjava)]

http://forums.java.net/jive/thread.jspa?messageID=268292

---------------------------------------------------------------------
To unsubscribe, e-mail: jdnc-unsubscribe@...
For additional commands, e-mail: jdnc-help@...


Re: how to use google map server with JXMapKit

by jdnc-interest :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

i have tried to use bluemarine class but i could not because TileFactoryInfo  class is not available under org.jdesktop.swingx.mapviewer package;

plz if u have any idea about how can i solve this problem reply as soon as possible;

thanks;
[Message sent by forum member 'crjava' (crjava)]

http://forums.java.net/jive/thread.jspa?messageID=268385

---------------------------------------------------------------------
To unsubscribe, e-mail: jdnc-unsubscribe@...
For additional commands, e-mail: jdnc-help@...


Re: how to use google map server with JXMapKit

by jdnc-interest :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I've a tilefactory and provider class for google maps. I'll contribute this classes the next few days to the swingx-ws project (I need only a developer access to jdic).

best regards,
  josh.
[Message sent by forum member 'arittner' (arittner)]

http://forums.java.net/jive/thread.jspa?messageID=268389

---------------------------------------------------------------------
To unsubscribe, e-mail: jdnc-unsubscribe@...
For additional commands, e-mail: jdnc-help@...


Re: how to use google map server with JXMapKit

by jdnc-interest :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

i have to present the project on Sunday, is there is any way to get the classes?

its a midterm presentation;
[Message sent by forum member 'crjava' (crjava)]

http://forums.java.net/jive/thread.jspa?messageID=268413

---------------------------------------------------------------------
To unsubscribe, e-mail: jdnc-unsubscribe@...
For additional commands, e-mail: jdnc-help@...


Re: how to use google map server with JXMapKit

by jdnc-interest :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

CRJAVA

Did you have success wiht the mouselistener? I work with Netbeans too. Basically i just registered the mouse listener to the mapkit like you did but I can't get it to work. If you can please give me pointer?

Thanks much!
[Message sent by forum member 'ngnguye' (ngnguye)]

http://forums.java.net/jive/thread.jspa?messageID=268435

---------------------------------------------------------------------
To unsubscribe, e-mail: jdnc-unsubscribe@...
For additional commands, e-mail: jdnc-help@...


Re: how to use google map server with JXMapKit

by jdnc-interest :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> i have to present the project on Sunday, is there is
> any way to get the classes?
>
> its a midterm presentation;

[b]You need only this simple class:[/b]
[code]
package org.sepix.sxwsgoogle;

import org.jdesktop.swingx.mapviewer.TileFactoryInfo;

public class GoogleTileFactoryInfo extends TileFactoryInfo {
  boolean sateliteView;
  public GoogleTileFactoryInfo (int minimumZoomLevel, int maximumZoomLevel, int totalMapZoom,
            int tileSize, boolean xr2l, boolean yt2b,
            boolean sateliteView) {
    super (minimumZoomLevel, maximumZoomLevel, totalMapZoom, tileSize, xr2l, yt2b, null, null, null, null);
    this.sateliteView = sateliteView;
  }
 
  @Override
  public String getTileUrl(int x, int y, int zoom) {
    if ( !sateliteView ) {
      return getMapUrl(x, y, zoom);
    } else {
      return getSatURL(x, y, zoom);
    }
  }
 
  protected String getMapUrl (int x, int y, int zoom)  {
    String url = "http://mt.google.com/mt?w=2.43" +
            "&x=" + x +
            "&y=" + y +
            "&zoom=" + zoom;
    return url;
  }

  /**
   * Not functional.
   * @param x
   * @param y
   * @param z
   * @return
   */
  public String getSatURL(int x, int y, int zoom) {
    int ya = 1 << (17 - zoom);
    if ((y < 0) || (ya - 1 < y)) {
      return "http://www.google.com/mapfiles/transparent.gif";
    }
    if ((x < 0) || (ya - 1 < x)) {
      x = x % ya;
      if (x < 0) {
        x += ya;
      }
    }

    StringBuffer str = new StringBuffer();
    str.append('t');
    for (int i = 16; i >= zoom; i--) {
      ya = ya / 2;
      if (y < ya) {
        if (x < ya) {
          str.append('q');
        } else {
          str.append('r');
          x -= ya;
        }
      } else {
        if (x < ya) {
          str.append('t');
          y -= ya;
        } else {
          str.append('s');
          x -= ya;
          y -= ya;
        }
      }
    }
    return "http://kh.google.com/kh?v=1&t=" + str;
  }
}
[/code]

[b]And follow usage:[/b]

[code]
TileFactoryInfo tfi = new GoogleTileFactoryInfo (0, 15, 17, 256, true, true, false);
mapKit = new JXMapKit();
mapKit.setTileFactory(tfi);
[/code]

best regards,
  josh.
[Message sent by forum member 'arittner' (arittner)]

http://forums.java.net/jive/thread.jspa?messageID=268475

---------------------------------------------------------------------
To unsubscribe, e-mail: jdnc-unsubscribe@...
For additional commands, e-mail: jdnc-help@...


Re: how to use google map server with JXMapKit

by Fabrizio Giudici :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Does this mean that we don't have any longer legal problems? Every  
time we talk about Google Maps I get more and more confused.

On Apr 10, 2008, at 10:14 , jdnc-interest@... wrote:

>> i have to present the project on Sunday, is there is
>> any way to get the classes?
>>
>> its a midterm presentation;
>
> [b]You need only this simple class:[/b]
> [code]
> package org.sepix.sxwsgoogle;
>
> import org.jdesktop.swingx.mapviewer.TileFactoryInfo;
>
> public class GoogleTileFactoryInfo extends TileFactoryInfo {
> boolean sateliteView;
> public GoogleTileFactoryInfo (int minimumZoomLevel, int  
> maximumZoomLevel, int totalMapZoom,
>           int tileSize, boolean xr2l, boolean yt2b,
>           boolean sateliteView) {
>   super (minimumZoomLevel, maximumZoomLevel, totalMapZoom, tileSize,  
> xr2l, yt2b, null, null, null, null);
>   this.sateliteView = sateliteView;
> }
>
> @Override
> public String getTileUrl(int x, int y, int zoom) {
>   if ( !sateliteView ) {
>     return getMapUrl(x, y, zoom);
>   } else {
>     return getSatURL(x, y, zoom);
>   }
> }
>
> protected String getMapUrl (int x, int y, int zoom)  {
>   String url = "http://mt.google.com/mt?w=2.43" +
>           "&x=" + x +
>           "&y=" + y +
>           "&zoom=" + zoom;
>   return url;
> }
>
> /**
>  * Not functional.
>  * @param x
>  * @param y
>  * @param z
>  * @return
>  */
> public String getSatURL(int x, int y, int zoom) {
>   int ya = 1 << (17 - zoom);
>   if ((y < 0) || (ya - 1 < y)) {
>     return "http://www.google.com/mapfiles/transparent.gif";
>   }
>   if ((x < 0) || (ya - 1 < x)) {
>     x = x % ya;
>     if (x < 0) {
>       x += ya;
>     }
>   }
>
>   StringBuffer str = new StringBuffer();
>   str.append('t');
>   for (int i = 16; i >= zoom; i--) {
>     ya = ya / 2;
>     if (y < ya) {
>       if (x < ya) {
>         str.append('q');
>       } else {
>         str.append('r');
>         x -= ya;
>       }
>     } else {
>       if (x < ya) {
>         str.append('t');
>         y -= ya;
>       } else {
>         str.append('s');
>         x -= ya;
>         y -= ya;
>       }
>     }
>   }
>   return "http://kh.google.com/kh?v=1&t=" + str;
> }
> }
> [/code]
>
> [b]And follow usage:[/b]
>
> [code]
> TileFactoryInfo tfi = new GoogleTileFactoryInfo (0, 15, 17, 256,  
> true, true, false);
> mapKit = new JXMapKit();
> mapKit.setTileFactory(tfi);
> [/code]
>
> best regards,
> josh.
> [Message sent by forum member 'arittner' (arittner)]
>
> http://forums.java.net/jive/thread.jspa?messageID=268475
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jdnc-unsubscribe@...
> For additional commands, e-mail: jdnc-help@...
>
>

--
Fabrizio Giudici, Ph.D. - Java Architect, Project Manager
Tidalwave s.a.s. - "We make Java work. Everywhere."
weblogs.java.net/blog/fabriziogiudici - www.tidalwave.it/blog
Fabrizio.Giudici@... - mobile: +39 348.150.6941



---------------------------------------------------------------------
To unsubscribe, e-mail: jdnc-unsubscribe@...
For additional commands, e-mail: jdnc-help@...


Re: how to use google map server with JXMapKit

by jdnc-interest :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> Does this mean that we don't have any longer legal
> problems? Every  
> time we talk about Google Maps I get more and more
> confused.

Yes you are right about the legal issues. I'll work on a TileFactory with the staticmap-url API.

best regards,
  josch.
[Message sent by forum member 'arittner' (arittner)]

http://forums.java.net/jive/thread.jspa?messageID=268496

---------------------------------------------------------------------
To unsubscribe, e-mail: jdnc-unsubscribe@...
For additional commands, e-mail: jdnc-help@...


Re: how to use google map server with JXMapKit

by jdnc-interest :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Arittner thanks for your fast reply;

i still have problem with jXMapKit1.setTileFactory(tfi);

setTileFactory takes TileFactory as parameter which takes TileFactoryInfo?

i have tried to create new tileFactory object and inserting tfi as parameter, however, i still have the same problem?
[Message sent by forum member 'crjava' (crjava)]

http://forums.java.net/jive/thread.jspa?messageID=268510

---------------------------------------------------------------------
To unsubscribe, e-mail: jdnc-unsubscribe@...
For additional commands, e-mail: jdnc-help@...


Re: how to use google map server with JXMapKit

by jdnc-interest :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

waaaaaaaw it is working ^_^

thanks a lot Arittner;

it is working be creating DefaultTileFactory

jxMapKit.setTileFactory(new DefaultTileFactory(tfi));

however, i didn't get it, what is the problem with mapKit.setTileFactory(tfi);

thanks again Arittner;
[Message sent by forum member 'crjava' (crjava)]

http://forums.java.net/jive/thread.jspa?messageID=268518

---------------------------------------------------------------------
To unsubscribe, e-mail: jdnc-unsubscribe@...
For additional commands, e-mail: jdnc-help@...


Re: how to use google map server with JXMapKit

by Fabrizio Giudici :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On Apr 10, 2008, at 11:49 , jdnc-interest@... wrote:
>> Does this mean that we don't have any longer legal
>> problems? Every
>> time we talk about Google Maps I get more and more
>> confused.
>
> Yes you are right about the legal issues. I'll work on a TileFactory  
> with the staticmap-url API.

Good. In my engineer's perspective the staticmap-url seems to be fine  
(because there are no more references to the "exclusive use of the  
Google APIs", the API now is just a HTTP GET), but I've got still  
fears about it. Does anybody know whether there's an explicit  
statement about the legal use of the staticmap-url from inside an  
applications? Hell, I'd rush to use it (and offer you a beer when you  
give a working TileFactory for it).

--
Fabrizio Giudici, Ph.D. - Java Architect, Project Manager
Tidalwave s.a.s. - "We make Java work. Everywhere."
weblogs.java.net/blog/fabriziogiudici - www.tidalwave.it/blog
Fabrizio.Giudici@... - mobile: +39 348.150.6941



---------------------------------------------------------------------
To unsubscribe, e-mail: jdnc-unsubscribe@...
For additional commands, e-mail: jdnc-help@...


Re: how to use google map server with JXMapKit

by jdnc-interest :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> >
> > Yes you are right about the legal issues. I'll work
> > on a TileFactory  
> > with the staticmap-url API.
>
> Good. In my engineer's perspective the staticmap-url
> seems to be fine  
> (because there are no more references to the
> "exclusive use of the  
> Google APIs", the API now is just a HTTP GET), but
> I've got still  
> fears about it. Does anybody know whether there's an
> explicit  
> statement about the legal use of the staticmap-url
> from inside an  
> applications?

A java application could be a browser ;-)

> Hell, I'd rush to use it (and offer you
> a beer when you  
> give a working TileFactory for it).

I need only a conversion from x/y/zoom coordinates to lat/long-coordinates, this should be easy to calculate.

But google provides only up to 512px*512px images and only 1000 images per day. And the key is bound to a web-domain. So I need direct access to the HTTP GET Communication and a "BrowserCache" for the tiles.

I've a ready-to-use transparent and file based "browser cache" implementation based on a ResponseCache-Interface. But the swingX-ws interface for Tiles is not handy to manipulate the Headers for the HTTP-GET communication.

some things to investigate ;-)

best regards,
  josch.
[Message sent by forum member 'arittner' (arittner)]

http://forums.java.net/jive/thread.jspa?messageID=268538

---------------------------------------------------------------------
To unsubscribe, e-mail: jdnc-unsubscribe@...
For additional commands, e-mail: jdnc-help@...


Re: how to use google map server with JXMapKit

by jdnc-interest :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> waaaaaaaw it is working ^_^
>
> thanks a lot Arittner;
>
> it is working be creating DefaultTileFactory
>
> jxMapKit.setTileFactory(new
> DefaultTileFactory(tfi));

*g* this was a test - sorry, I just kidding.

> thanks again Arittner;

Please note the legal issues about retrieving the tile-images without the javascript API.

best regards,
  josch.
[Message sent by forum member 'arittner' (arittner)]

http://forums.java.net/jive/thread.jspa?messageID=268540

---------------------------------------------------------------------
To unsubscribe, e-mail: jdnc-unsubscribe@...
For additional commands, e-mail: jdnc-help@...


Re: how to use google map server with JXMapKit

by jdnc-interest :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Arittner what do you mean by "Please note the legal issues about retrieving the tile-images without the javascript API"

is there is any way for them to block my IP address from using the map??
[Message sent by forum member 'crjava' (crjava)]

http://forums.java.net/jive/thread.jspa?messageID=268548

---------------------------------------------------------------------
To unsubscribe, e-mail: jdnc-unsubscribe@...
For additional commands, e-mail: jdnc-help@...


Re: how to use google map server with JXMapKit

by jdnc-interest :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> Arittner what do you mean by "Please note the legal
> issues about retrieving the tile-images without the
> javascript API"
>
> is there is any way for them to block my IP address
> from using the map??

Your Google-Key get blocked, if you send more than 10000 request per day. But the TileFactory does not need any google key.

The main issue is the restriction to the javascript google maps api. The JXMapViewer (and helper classes) calls the map server directly. This is a legal rights problem not a technical problem.

please follow this link: http://www.google.com/help/legalnotices_maps.html

best regards,
  josch.
[Message sent by forum member 'arittner' (arittner)]

http://forums.java.net/jive/thread.jspa?messageID=268581

---------------------------------------------------------------------
To unsubscribe, e-mail: jdnc-unsubscribe@...
For additional commands, e-mail: jdnc-help@...


Re: how to use google map server with JXMapKit

by jdnc-interest :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi there, thanks for the work:)  One problem however - i can get it all to work with the Google Street maps (when using your recomended usage), but i can't get it to work with the Google Satellite Maps.  I get the error:

[i]SEVERE: Failed to load a tile at url: http://kh.google.com/kh?v=1&t=tsqqqqqqqqqqqqqqq, retrying
[/i]

Would you be able to give me a way to use the Satellite Maps?

Thanks alot
[Message sent by forum member 'chris414' (chris414)]

http://forums.java.net/jive/thread.jspa?messageID=288438

---------------------------------------------------------------------
To unsubscribe, e-mail: jdnc-unsubscribe@...
For additional commands, e-mail: jdnc-help@...


Re: how to use google map server with JXMapKit

by jdnc-interest :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,
First thanks a lot, but I have the same probleme than you, chris414.
Have you found the solution ?
[Message sent by forum member 'condor1' (condor1)]

http://forums.java.net/jive/thread.jspa?messageID=296553

---------------------------------------------------------------------
To unsubscribe, e-mail: jdnc-unsubscribe@...
For additional commands, e-mail: jdnc-help@...

LightInTheBox - Buy quality products at wholesale price