From Documentation

Jump to: navigation, search




  • Author
    Jeff Liu, Freelance Senior Web Application Developer, jebberwocky@gmail.com
  • Date
    October 14, 2010
  • Version
    ZK Gmaps 2.0


Contents

Introduction

A controversial article was published 2 years ago, ZK vs. GWT : Server-Centric Matters!, which caused a large amount feedbacks on this topic. After 2 years , both frameworks have improved greatly. As the author of this article, rather than continue this debate, I will finish off the technology.

In the article, one sample was used to demonstrate the difference between ZK and GWT, Google Maps Locator. A fake geocoding class was used to locate the latitude and longitude for a certain address, which does nothing but couple exiting data. To actually geocode the latitude and longitude in Java, Google Geo Kit in Java is introduced.

Google Geo Kit in Java

Google Geo Kit in a java is an implementation of Google Geocoding API in Java, refer to http://code.google.com/apis/maps/documentation/geocoding/. A simple demonstration of it's usage is following.

SpotInfo sinfo = new SpotInfo();
sinfo.Address = "1600+Amphitheatre+Parkway,+Mountain+View,+CA";
Geocoder geo  = new Geocoder();
GeoResult result = geo.GetGeoResult(sinfo);
if (GeoResultStatus.OK.Equals(result.Status))//@since 0.1.1
{
	foreach (GeoObj obj in result.Results)
	{
		Response.Write(obj.FormattedAddress + "<br>");
	}
}

Work with ZK Gmaps

<zk>
    <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=KEY" type="text/javascript" >
    </script>
    <window>
        <div align="center">
            <vbox width="600px">
                <textbox id="tb" width="550px" value="1600+Amphitheatre+Parkway,+Mountain+View,+CA" />
                <button onClick="locate();" label="Search" />
                <gmaps id="mymap" zoom="16" height="300px" />
            </vbox>
        </div>
        <zscript>
        import org.zkoss.gmaps.Ginfo;   
        import org.gglgeo.ggl.GeoInfo;
		import org.gglgeo.ggl.GeoLatLng;
		import org.gglgeo.ggl.GeoObj;
		import org.gglgeo.ggl.GeoResult;
		import org.gglgeo.ggl.Geocoder;  
		          
        public void locate(){  
        	GeoInfo info = new GeoInfo();
			info.setAddress(tb.getValue());
			Geocoder gcoder = new Geocoder();
			GeoResult gresult = gcoder.get(info);
/*According to Google Geocoding API, "results" contains an array of geocoded address information and geometry information, 
getResult will return array of result objects rather than single one.*/
			GeoLatLng latlng = gresult.getResults().get(0).getGeometry().getLocation();
            mymap.panTo(latlng.getLat(), latlng.getLng());
            alert(gresult.getResults().get(0).getFormattedAddress());       
        }
        </zscript>
    </window>
</zk>

Download

Thanks All

I left the ZK development team 2 years ago to start my own startup but I still pay attention to ZK and its development. It have improved greatly during the past 2 years. Thanks for all the people from Potix for what I have learned during my time there and after.

For any questions, please contact: jebberwocky@gmail.com



Copyright © Potix Corporation. This article is licensed under GNU Free Documentation License.
You got stuck here?
Let us know why!
For questions please use the forum