Thursday, April 28, 2011

Using Google Refine and Google Maps API to calculate distance between two addresses


Distance Calculation Using Refine and Google Maps API:

·         Create two columns
o   Origin – origin address (address can be anything – complete address, just city, start, zip, country or any combination of tose]
o   Destination – destination address
·         Create a new column “distance api response” based on Origin column using the url option

Copy this in expression field show below [if you use the column names Origin and Destination, you don’t have to change anything in this formula]
"http://maps.googleapis.com/maps/api/directions/json?origin="+escape(value, "url")+"&destination="+escape(cells["Destination"].value, "url")+"&sensor=false"



        
               
·         Create a new column called “distance” – create it based on “distance api response” column and use the following formula in the expression
with(value.parseJson().routes[0].legs[0].distance,pair,pair.text)

Monday, April 18, 2011

How to get GWT DateBox to show only the date part

While searching for tips on this, I found this useful blog post.
The only change i made is I replaced the deprecated function
getShortDateFormat with getFormat method from DateTimeFormat class.

With deprecated method:
So to format a DateBox to display a date like 06/26/2009
dateBox = new DateBox();
dateBox.setFormat(
new DateBox.DefaultFormat(
DateTimeFormat.getShortDateFormat()));

With new method:
fromDate = new DateBox()
fromDate.setFormat(
new DateBox.DefaultFormat(
DateTimeFormat.getFormat(PredefinedFormat.DATE_SHORT)));

Saturday, April 16, 2011

Date Operations in GWT

Standard java class java.util.Calendar does not work in GWT. Instead, use GWT class com.google.gwt.user.datepicker.client.CalendarUtil.



Similarly, for formatting and parsing date/time, use com.google.gwt.i18n.client.DateTimeFormat


Convert Date to String - Format

DateTimeFormat.PredefinedFormat.DATE_SHORT).format(newDate())



Convert String to Date - Parse

DateTimeFormat.getFormat(DateTimeFormat.PredefinedFormat.DATE_SHORT).parse(dateString)