DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Overcoming Some Pitfalls of the Google Maps API
  • 7 Best Applications for Making Geographical Maps
  • Why Google Data Migration Gets Stuck at 99%: Causes and Proven Fixes
  • Run Gemma 4 on Your Laptop: A Hands-On Guide to Google's Latest Open Multimodal LLM

Trending

  • The Twelve-Factor Agents: Building Production-Ready LLM Applications
  • Engineering Production Agentic Systems: Part 1: The Pipeline
  • Building Reliable Async Processing Pipelines Using Temporal
  • Slopsquatting: Building a Scanner That Catches AI-Hallucinated Packages Before They Reach Production

Google Maps for JSF

By 
Himanshu Gupta user avatar
Himanshu Gupta
·
Apr. 22, 10 · Interview
Likes (0)
Comment
Save
Tweet
Share
22.8K Views

Join the DZone community and get the full member experience.

Join For Free

gone are the days when you have to open an atlas for looking some location. thanks to google maps which shows you whatever you want and that too within minutes. you can’t only see the location but also get its real time traffic details with lots of other information. is not it cool to show your location in google map on your website or blog so that everyone can know where you are living or working?

gmaps4jsf is the extensive library provided by the google to integrate google maps in jsf enabled pages. gmaps4jsf aims at integrating google maps with jsf. jsf users will be also able to construct complex streetview panoramas and maps with just few lines of code (jsf tags). it allows you to mark polygons, lines, html informatin window to your map. gmaps4jsf is one of the jsf mashups libraries that enables jsf users to build web 2.0 mashup applications in jsf easily.

configuring gmap4jsf

you really don’t have to do much to use google maps with your jsf framework. you only need to follow these given steps:

  1. download the gmaps4jsf-core-1.1.jar from http://code.google.com/p/gmaps4jsf/downloads/list and put it in your project’s lib folder.
  2. include the tag library in your jsf page as follows:
    view source print ?
    1 <%@ taglib prefix="c" uri=" http://java.sun.com/jsp/jstl/core "%>
  3. add the following script tags in your jsp head tags.

    < script src="http://maps.google.com/maps?file=api&v=2&key=abqiaaaaxrvs1qxlpjhxxq2vxg2bjbqdkfk
    -twrbppqs4acm1pq_e-pltxqxeyh20wquqdaq_6em5ueggvpniw" type="text/javascript">
    < /script >

    the key which is used in javascript can be generated by signing up at http://code.google.com/apis/maps/signup.html

embedding google map in jsf page.

after doing the above mentioned tasks you are all ready to insert map in your jsf page. this is the basic structure of a jsf page which is ready to incorporate google map in it.

<%@ page language="java" contenttype="text/html; charset=iso-8859-1"
pageencoding="iso-8859-1"%>
<%@taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%@ taglib uri="http://code.google.com/p/gmaps4jsf/" prefix="m"%>
<!doctype html public "-//w3c//dtd html 4.01 transitional//en" "http://www.w3.org/tr/html4/loose.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<script
src="http://maps.google.com/maps?file=api&v=2&key=abqiaaaaxrvs1qxlpjhxxq2vxg2bjbqdkfk- twrbppqs4acm1pq_e-pltxqxeyh20wquqdaq_6em5ueggvpniw"
type="text/javascript"></script>
<title>insert title here</title>
</head>
<body>
<f:view>
<h:form id="form">
<m:map zoom="16" width="500px" height="500px" address="white house">
<m:mapcontrol name="glargemapcontrol" position="g_anchor_bottom_left" />
<m:mapcontrol name="gmaptypecontrol" />
<m:htmlinformationwindow htmltext="white house"></m:htmlinformationwindow>
</m:map>
</h:form>
</f:view>
</body>
</html>

explanation

<%@ taglib uri="http://code.google.com/p/gmaps4jsf/" prefix="m" %>

as described before the include directive tag imports the usable taglib and uses m as its prefix

<m:map zoom="16" width="500px" height="500px" address="white house" >
<m:mapcontrol name="glargemapcontrol" position="g_anchor_bottom_left"/>
<m:mapcontrol name="gmaptypecontrol"/>
<m:htmlinformationwindow htmltext="white house"></m:htmlinformationwindow>
</m:map>

  • <m:map> is for map component. it allows us to create a map. it has various attributes which can be used to customize it. none of them are compulsory. so you are free to use them or not according to ypur needs.
    • zoom: its default value is 11. you can change its value as per your requirements.

    • width and height: they represent the height and width of the map. the default values are 500 for both.

    • address: the address you wish the map to point to. if you use this attribute then don't use longitude or latitude attributes.

  • <m:mapcontrol> this component allows us to add a map control to the map component. like if you want to add a control so that the user can zoom in or zoom out the map, or a control to switch between the types of the map.


  • htmlinformationwindowcomponent: this component allows us to add an information window to the map component. following we have provided the description about their attributes.

  • from http://himanshugpt.wordpress.com/2010/04/21/google-maps-for-jsf/

    Google Maps Google (verb)

    Opinions expressed by DZone contributors are their own.

    Related

    • Overcoming Some Pitfalls of the Google Maps API
    • 7 Best Applications for Making Geographical Maps
    • Why Google Data Migration Gets Stuck at 99%: Causes and Proven Fixes
    • Run Gemma 4 on Your Laptop: A Hands-On Guide to Google's Latest Open Multimodal LLM

    Partner Resources

    ×

    Comments

    The likes didn't load as expected. Please refresh the page and try again.

    • RSS
    • X
    • Facebook

    ABOUT US

    • About DZone
    • Support and feedback
    • Community research

    ADVERTISE

    • Advertise with DZone

    CONTRIBUTE ON DZONE

    • Article Submission Guidelines
    • Become a Contributor
    • Core Program
    • Visit the Writers' Zone

    LEGAL

    • Terms of Service
    • Privacy Policy

    CONTACT US

    • 3343 Perimeter Hill Drive
    • Suite 215
    • Nashville, TN 37211
    • [email protected]

    Let's be friends:

    • RSS
    • X
    • Facebook