My favorites | Sign in
Logo
                
Search
for
Updated Jan 05, 2009 by Hazem.saleh
HowToUseTheLibrary  

How to configure the library:

  • Place the the latest library jar in your web application WEB-INF/lib folder.
  • Include the tag library in your JSF page as follows:
  •  <%@ taglib uri="http://code.google.com/p/gmaps4jsf/" prefix="m" %>
and NEVER forget to include the Google maps script include in your page HEAD tag like:
<script

src="http://maps.google.com/maps?file=api&amp;v=2&amp;
key=ABQIAAAAxrVS1QxlpJHXxQ2Vxg2bJBT2yXp_ZAY8_ufC3CFXhHIE1NvwkxS9AOPy_YJl48ifAy4mq6I8SgK8fg"
type="text/javascript">

</script>     
  • Done!!!

Example of usages:

  • To create a simple map (Using longitude and latitude), do the following:
  •  <m:map width="500px" height="500px" latitude="30.01" longitude="31.14" />

This will create a simple map of height = 500px and width = 500px, and the map will point to latitude = 30.01 and longitude = 31.41.

  • To create a map with markers and HTML information windows, do the following:
  •  <m:map width="500px" height="500px" latitude="30.01" longitude="31.14">
    
        	<m:marker latitude="30.01" longitude="31.14"/>
    
        	<m:htmlInformationWindow latitude="30.01" longitude="31.14" 
    
        	htmlText="<B>Egypt</B>"/>
    
    </m:map>

This will add a marker and an HTML information window to your map at latitude = 30.01 and longitude = 31.41, and the HTML information window will display the value in the (htmlText) attribute.

  • To create a simple map (Using address), do the following:
  •   <m:map address="#{addressBean.address}">
    	 <m:marker/>
    	 <m:htmlInformationWindow htmlText="#{addressBean.address}"/>
      </m:map>

This will create a simple map that will point to the specific address with the marker and an information window containing the address.

  • To add controls to your map, use the <m:mapControl .../> tag:
  •     	<m:map width="500px" height="500px" latitude="30.01" longitude="31.14">
        	       <m:mapControl name="GLargeMapControl" position="G_ANCHOR_BOTTOM_RIGHT"/>
        	       <m:mapControl name="GMapTypeControl"/>    			
        	</m:map>

This will add two controls on the map. The first control is the (GLargeMapControl) -its position will be in the bottom right of the map- , and the second control is the (GMapTypeControl) which enables switching between map types.

  • To attach events to your map or marker, use the <m:eventListener.../> tag:
  •     <m:map width="90%" height="90%" latitude="24" longitude="15">   			
    	<m:eventListener eventName="moveend" jsFunction="mapMoveEndHandler"/>		
        </m:map>

This will create an event listener to the map, which will execute the (mapMoveEndHandler) function when the map (moveend) event occurs.

  • To attach a polygon (a closed set of lines) to your map, use the <m:polygon .../> tag:
  •    	<m:polygon lineWidth="4">
       		<m:point latitude="30.01" longitude="31.14"/>
       		<m:point latitude="-33" longitude="19"/>    				
       		<m:point latitude="39" longitude="-101"/>  	
       		<m:point latitude="30.01" longitude="31.14"/>
        	</m:polygon>

This will attach a polygon of the listed four points to the map. Note that the first point should be the same as the last one.

  • To attach a polyline (an opened set of lines) to your map, use the <m:polyline .../> tag:
  •     	<m:polyline>
        		<m:point latitude="30.01" longitude="31.14"/>
        		<m:point latitude="-33" longitude="19"/>    				
        		<m:point latitude="39" longitude="-101"/>
        	</m:polyline>

This will attach a polyline of the listed three points to the map.

  • To attach an image to your map, use the <m:groundoverlay .../> tag:
  •     <m:map width="90%" height="90%" latitude="24" longitude="15" zoom="2">
                     <m:groundoverlay imageURL="http://www.jroller.com/HazemBlog/resource/gmaps4jsf-logo.png" 
                      startLatitude="7" endLatitude="23" 
        		  startLongitude="-54" endLongitude="84" />    			
        </m:map>

This will attach the GMaps4JSF logo to the map, placing the image in the box starting from latlng(7, -54), and ending at latlng(23, 84).

  • To create a street view panorama, use the <m:streetViewPanorama .../> tag:
  •     <m:streetViewPanorama width="500px" height="500px" 
        			  latitude="42.345573" longitude="-71.098326" />
    

This will create a simple street view panorama of height = 500px and width = 500px, and the panorama will point to latitude = 42.345573 and longitude = -71.098326.

  • For more information about how to use the several components, please see the examples in the demo, and the tag library documentation.

Comment by bt2000, Oct 16, 2008

map still not showing up

Comment by sheldonshi2008, Oct 17, 2008

I used this API on Google Maps' China service http://ditu.google.com/... Many of the tags do not work, such as showing the map control, and using jsVariable to refer the map. (Same code works for maps.google.com service.) Do you know if this is because ditu.google.com does not provide the full API that maps.google.com offers?

Sheldon

Comment by aris...@hotmail.com, Nov 26, 2008

I used the library at my Jboss Seam project. I changed the web.xml to support facelets and although it seems to transact with google.com the map is still not showing up. I don't know if this is an issue so I posted it here. Any idea?

Comment by Hazem.saleh, Nov 26, 2008

@aris: I will make a sample on JBoss seam and upload it soon! Thanks for telling us.

Comment by aris...@hotmail.com, Nov 26, 2008

Thanks for the really fast reply. Looking forward...

Comment by chad.retz, Dec 05, 2008

This is caused by the jar not conforming to facelets taglib rules: https://facelets.dev.java.net/nonav/docs/dev/docbook.html#taglib-web

Just open the jar and rename gmaps4jsf-facelets.xml to gmaps4jsf.taglib.xml and the tag will be properly parsed. Now for the map showing up properly...that's a whole different story

Comment by Hazem.saleh, Dec 06, 2008

GMaps4JSF works fine with Facelets, and the map is shown up, check this: http://gmaps4jsf.googlecode.com/files/gmaps4jsf1.1.1-facelets.war

Comment by Hazem.saleh, Dec 06, 2008

Please if any body finds a specific case or issue, Can s(he) open an issue here: http://code.google.com/p/gmaps4jsf/issues/list

Comment by echoqian, Jan 13, 2009

The google map works fine in my page, but if I add <m:streetViewPanorama /> componment, the map does not work anymore and pops up "Stack overflow" error.

Comment by ibalashov, Jan 24, 2009

Has anybody checked if addresses in native languages are supported? If I put an address string in Russian it gives me "(GClientGeocoder) service not found the address location". I wonder if page encoding might be not correct (utf8 was used).

Comment by ibalashov, Jan 25, 2009

@ibalashov Turned out to be a GET encoding issue. Solved with putting useBodyEncodingForURI="true" into Tomcat's server.xml

Comment by sotcommy, Apr 07, 2009

i'm using gmaps4jsf with icefaces. apearantly the initializing js method of the map isn't called when a ajax request is done. this leads to a blank map. any1 got a workaround for that? greetings and thanks

Comment by brent.frederick, May 29, 2009

I'm having the same issue with Icefaces...

Comment by Hazem.saleh, May 29, 2009

@sot, @ brent:

Did you try the latest snapshot (http://gmaps4jsf.googlecode.com/files/gmaps4jsf-core-1.1.2-SNAPSHOT-28-May-2009.jar)

If you try it and it causes the same bug, I appreciate if you open an issue, and send me a link to your war so I can solve this defect if exists.

Thanks!

Comment by brent.frederick, Jun 03, 2009

To get it working with IceFaces?, put this in the constructor of your backing bean:

import com.icesoft.faces.context.effects.JavascriptContext?;

JavascriptContext?.includeLib("http://maps.google.com/maps?file=api&amp;v=2&amp;key=abcdefg", FacesContext?.getCurrentInstance());

Comment by brent.frederick, Jun 09, 2009

For IceFaces? partial rendering to work, you must set the renderOnWindowLoad attribute for the Gmaps4JSF:

This flag determines whether to render the map on window load. This flag should be set to false if the map is inside a zone that will be updated by Ajax.
<m:map width="800px" height="600px" autoReshape="true" type="G_HYBRID_MAP" renderOnWindowLoad="false">
Comment by girish.ahankari, Sep 03, 2009

Hi Hazem We use gmaps4JSF gmaps4jsf-core-1.1.2-SNAPSHOT-20-June-2009.jar Liferay portal server5.2.2 icefaces1.8.0 After using the attribute renderOnWindowLoad="false", we are able to see map in few locations. But it does not work in few places, gives a blank screen. Works fine in IE7 but gives problem in IE8 with VISTA and Firefox3.5 on Windows XP and Vista. If I see view source, i can see the Gmap script there.. but map is not rendered. May be the initialization code is not getting rendered.. blank screen looks bad... Can you please help.

Comment by r...@notify.co.uk, Sep 29, 2009

Getting the same problem as Girish etc. The m:map doesn't render my map.

I using the GMaps4JSF 1.1.2 jar

If I add the RichFaces? gmap tag;

<rich:gmap/>

Both maps render!

Comment by codehtmai, Oct 23, 2009

Using 1.1.2 with ICEfaces, also can't get the map to show up :(

Tried the renderOnWindowsLoad="false", no luck.

Comment by codehtmai, Oct 23, 2009

I got it! I added more standard JSF libraries to my project. Hope this helps someone else.

Comment by r...@notify.co.uk, Nov 04, 2009

I added more standard JSF libraries to my project

Can you expand? Which libraries did you add?


Sign in to add a comment
Hosted by Google Code