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)










Saturday, March 26, 2011

Data Nucleus Enhancer Errors

It appears like there is a limit on how many classes can be enhanced in google app engine projects on eclipse. If there are too many classes, you get the following error ("CreateProcess error=87, The parameter is incorrect") at the build time and some classes do not get enhanced. 




If you try to use the application, you get errors that look like the following:



[ERROR] Excepton in class: javax.jdo.JDOUserException
[ERROR] Persistent class "Class so&so does not seem to have been enhanced.  You may want to rerun the enhancer and check for errors in the output." has no table in the database, but the operation requires it. Please check the specification of the MetaData for this class.

How to fix?
In reality, all classes do not need to be enhanced. You can restrict it to a limited set of classes by changing ORM settings under App Engine settings in Eclipse




Friday, March 11, 2011

SuggestBox with UIBinder

Using SuggestBox with in UIBinder is not straighforward. This article explains how to do it.

Monday, February 14, 2011

Download and Upload bulk data to Google App Engine

The bulk loader tool can upload and download data to and from Google App Engine's datastore. This pdf document has step by step instructions.

Saturday, January 22, 2011

How to programmatically log errors, warnings and info messages in google app engine

Google app engine documentation provides info on how to log server side errors, warnings or info messages in Python environment but there is no clear documentation on how to do the same in java environment. Here is an example of logging in java environment

import java.util.logging.Logger;
private static final Logger log = Logger

.getLogger(MyClass.class.getName());
public class MyClass {

public myMethod() {
 
                        log.info("Informational message");

                        log.warning("warning");
log.severe("severe error");


}

}

When deployed to App Engine, you can find the logs app engine admin console



In Dev mode (if using Eclipse), you can see the logs on Eclipse console