Skip to content

Latest commit

 

History

History
111 lines (79 loc) · 5.25 KB

Readme.md

File metadata and controls

111 lines (79 loc) · 5.25 KB

#Socrates, a sage google places client.

Did you search for a component responsible for Google Places query and retrieving result and, finally, bind it into java class? There is Socrates.

Why Socrates? Because, as homonim philosopher said: "sage goes to the market to see, not to buy".

And so Socrates component just search (google) places.


###usage:
Location here = ... // my last best location
Searcher placesSearcher = ... // manually istanced via getInstance, or use @Inject
placesSearcher.initFromConfig(); // see below for details about config
SearchResponse searchResponse = placesSearcher.search( here ); // or placesSearcher.initFromConfig.search(here);
List<Place> places = searchResponse.getStatus().handleStatusAndGetData(searchResponse);
Place is a class mapping json/xml response fields by google search response: [see here](http://developers.google.com/maps/documentation/places/#PlaceSearchResults)
do you want Place Details ?
String reference = place.getReference();
DetailsRetriever detailsRetriever = .. // manually istanced via getInstance, or use @Inject
DetailsResponse placeDetailsResponse = detailsRetriever.retrieveDetails( reference );
Details placeDetails = placeDetailsResponse.getStatus().handleStatusAndGetData(placeDetailsResponse);
Details is (again) a class mapping json/xml response fields by google detail response: [see here](https://developers.google.com/maps/documentation/places/#PlaceDetailsResults)

And something about ConfigMandatory and ConfigOptional:
they are interfaces used by components Searcher and DetailRetriever, and they provide needed values in order to build request (see here):

public interface ConfigMandatory {
	public String getKey(); // Google Places api key
	public String getApplicationName(); // clear, isn't ?
	public HttpParserOutputType getOutput();	// json or xml
	public boolean isUseSensor(); // true if use location sensor (always with android)
}

and

public interface SearcOptions {
	public Integer getRadius(); // radius within into we search
	public Set getTypes(); // types we're interesting for: see [types](https://developers.google.com/maps/documentation/places/supported_types)
	public List getNames(); // words within places name - for accurate filter query search
	public RankBy getRankBy(); // the order in which results are listed: distance or prominence (achtung - default if not specified)
	public String getKeyword(); // A term to be matched against
	public Language getLanguage(); // The language code, for localized results
}

in your application you have to implements these two interfaces, in your preferred way.

Simple classes wrapping all values? Any xml parsers reading values from xml conf files? Other solutions?

If you use roboguice: Choise, implement and finally bind via module (and i recommend as singleton) ;D

First interface methods implementation is all mandatory (as the name), while the second not:
your class will return only really used options, and "null" elsewhere.
But careful! According to reference you have to provide radius if rankby is not specified (and it is "prominence" as default), or you have not to include it if "rankby" is "prominence", but one or more of "keyword","name","types" if rankby is "distance" have to be included

Searcher class provides a method "setSearchOptions" requesting SearchOptions, if u want change (temporary) your target search
With "resetSearchOptions" method you can return to default config provided via constructor.



In order to compile correctly you have to put various jar in "libs" directory (then move all them in main project "libs" directory):

from google api java client:

from roboguice:

and don't forget to change place api key with your own!






heavily ispired by: http://ddewaele.blogspot.it/2011/05/introducing-google-places-api.html