How to use google place API in android app effectively - java

There are multiple options to use with AutoCompleteTextView,
calling api to server and let server control suggesting auto complete places proxying google APIs, considering control to throttle the rate
calling directly from client to google API on raw rest API and parsing response JSON
is there a Java client for google place API already available that abstracts parsing and other parts and respects current location to add context to what user might be looking for and other contextual data about user to fine tune search ? if so an example would be great pointer
what is the common practice around here

To answer your last question, I have developed both a pure Java client for the Google Places API (Sprockets for Java) and an Android library project (Sprockets for Android) that builds on top and provides classes like GooglePlaceAutoComplete and GooglePlacesLoader.
After setting up the library, adding a GooglePlaceAutoComplete widget to your app is just a single tag in a layout (example below). In your Activity or Fragment, you can also register an OnPlaceClickListener that is called when the user chooses a suggested place.
<net.sf.sprockets.widget.GooglePlaceAutoComplete
android:id="#+id/place"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>

Sounds like you need some documentation to make decisions. A good place to start is, of course, the google places api for android section. I think you will find here all the info you need.
calling api to server and let server control suggesting auto complete
places proxying google APIs, considering control to throttle the rate
calling directly from client to google API on raw rest API and parsing
response JSON
I would go for the the first option if I would have an application that will need some limitations of request and data gathering about maybe who/where/when your requests are made, this being(I think) the best solution to control your billing and keep yourself the track of requests. The second solution it is not bad either, but keep in mind that you will enconde your google places api key in your application! More about the billing and usage limitations here.
is there a Java client for google place API already available that
abstracts parsing and other parts and respects current location to add
context to what user might be looking for and other contextual data
about user to fine tune search ? if so an example would be great
pointer
On the same website you will find samples of how to use google places api in your applications. For autocomplete check this out.

Related

Video Streaming on website using java

I am developing a website where users can upload and watch videos. I have never done anything like this before and needs some guidance. I want the videos to be stored on my server and users can search and watch them from a video player on my website. What are the java libraries to implements this and what are the other technologies I will need.
Here's a list of Technologies you can consider to use or study.
JSP + Servlet = You would implement your own MVC
implementation(Though I would not recommend this if you are building
a large scale application unless you are really good at it. Consider
Number 2)
Consider To Use an MVC framework(like Struts2, Spring MVC etc.) or
like what Thorn Said, a REST framework like Jersey(Though I have not
tried using a REST framework).
Database Access - Do I need to explain why?
An ORM library - using an ORM can speed up development(this can be
subjective though), it makes data access more abstract and
portable,ORM implementation classes know how to write
vendor-specific SQL.
File Upload library - if you are going to use as Struts2 your
framework once of its depencies is the Apache Commons Library(Just
check their documentation).
You've said that the users will upload their videos and you will store them in your server
and you will play those videos in their web-browser you need to do File convertions, Why?
in HTML5, since not all browsers support all video formats, so you need to consider
converting the video to another format if you are going for an html5 player. you can check out different file formats that different browser supports here
For File conversion check this Here
Now for the client side video, you can Use the MediaElement.js it has a flash fallback, just in case that users video does not support HTML5.
First check out this for your player:
Player
Now your logic needs to be a little different. You should make thumbnails of the videos and send them to the player with a link. This way you only need one setup of the player and pass the url information into it.
Rather than starting this project with a list of technologies you need to master, I would recommend starting with an outline of what you want it to look like - how will the user interact with the site? What functionality will it have and how do you want this exposed to the user?
Next I would think about the data. How will it be stored? How will the video files be names and associated with users? What attributes of the videos do we need to store? For example, each video file can have an associated user (who posted it), some attributes, like date, file size, resolution, frame rate. Will we also be storing comments or ratings? Keywords? A Description?
Probably you will want a database to store this data, but I would just store the video files as regular files in the directory.
Now onto choosing a set of tools to get this done...
Java Servlets or a REST framework like Jersey.
File upload using an Apache commons library (probably no need for this if using Jersey framework)
Database access
HTML 5 video playback or Flash video or JavaFX 2
With HTML5 (browser based video playback without a plug-in) is not supported on all browsers yet.
A search feature could also be done in Java. You would need some database skills here and to do search well is far from trivial. But a basic search where you give the application a keyword and it gives you all videos listing this keyword should be simple.

How do I use Google Maps API in a Java code to fetch coordinates of specified location?

In a BI project I'm currently working on, we are in need of geo-coordinates for a list of locations. With the address location (such as "New York, US") as input, the output should be the coordinates as a latitude-longitude pair (like {40.71435, -74.00597}). The behaviour is similar to what is seen on this page.
A similar question earlier on SO points to using the Google Maps API in JavaScript to achieve this, but I'm looking for a Java solution -- some function of the form getCoordinates(location), because this is a small requirement in a larger Java program already in existence.
Any pointers on how I may use the Google Maps API (or any other maps API) in Java to achieve this would be of great help!
You can use the Google Geocoding HTTP API (see here).
To connect to it and get the responses you can use a Java URLConnection (tutorial is here) and parse the response using your favourite Json library (I personally use Jackson)
So you'd like a way to perform Google Maps API Geocoding via Java - here's one that might work for you. The response might not be in the exact same format you need but should be pretty workable:
http://code.google.com/p/geocoder-java/
You can see the final format returned in LatLng.java - just trace the code through starting from GeocodeResponse.java and you'll see the final format - the classes are pretty simple.

Android - Obtaining data from a website

I'm finding my way around Android and so far so good. My next big challenge is coming to grips with web services. I would like to build an app that reads data from a web site or database on web server and store the data in my app.
Basically, it will be an app that I build in conjunction with a news website that pulls their latest articles into the app. What I'm finding difficult is how to bridge the gap between my application and the data in the SQL Server database.
I'm familiar with building asp websites that read data from a database, but how would I do something similar with an app?
Do I ask the website to store the articles in an xml format? Or, is there another way that I can request a specific article and be provided with the content?
I hope I'm phrasing the question correctly and that someone can just guide me to the right way to approach this.
Thanks in advance.
You can approach this problem from different perspectives.
The common solution is to build a Webservice that will bridge the gap between your mobile application and the data that remain in your server. I personnaly prefer to setup a Rails backend and thus have a RESTful API that will help me access my data. For instance, to retrieve the list of articles I could just request the following url: http://my_server_host/articles. So for the Webservice part you can have whatever you want: Rails, J2EE, .NET etc. And you can choose the model that fits your needs (REST, SOAP, XML-RPC etc.).
Then you will have to write a class that will contain all the necessary calls to the Webservice you have built. Basically, if your Webservice returns the results as an XML format you will have to:
Send the request to the appropriate URL. (See: HttpGet or HttpPost if you want to modify a resource).
Parse the XML returned. (In short, you can use SAX or DOM to parse your XML response and transform them to a business entity (an Article, a User etc.).)
This hopefully gives you a hint about a possible solution. By the way Google is your friend, but I will probably come back to add external links/resources to help you more.
Edit
Another possible solution that could work for you, since all you need is to retrieve some articles. Just setup a simple Wordpress blog for instance. Wordpress gives you an URL for the blog's RSS feed, all you will have to do is to parse that RSS feed (XML). There is a great article on the IBM website for parsing an RSS feed that you can find here. By the way, this solution is only possible if you want to save your articles on a Wordpress blog. But you got the point hopefully.
Reading your data form the Database on the Server would be bad practice. You'd have to open up some ports and that's defiantly not what you want (if you don't have root-access, you also can't).
For non-interactive content (what you want) you would use XML or JSON.

In an Android application, should I have one content provider per table or only one for the entire application?

I have years of experience with Microsoft .NET development (primarily C#) and have been working to come up to speed on Android and Java. So far, I've built a small application with a couple screens and a working content provider.
All of the examples I've seen for developing content providers typically work with a single table, so I got the impression that this was the convention.
I built a couple more content providers for other tables and ran into the "Unknown URI" IllegalArgumentException when I tried to test them. The exception is being thrown by one of my content providers, but not the one I was intending to call.
It appears that my application is using the first content provider in the AndroidManifest.xml file, which now has me wondering if I should only have a single content provider for the entire application.
Are there any best practices and/or examples for working with multiple tables in an Android application? Should I have one content provider per table or only one for the entire application? If the former, how do I resolve URIs to the proper provider? If the latter, how do I keep my content provider code from being polluted with switch statements?
Well i have to disagree with CommonsWare.
If you want to avoid IllegalStateExceptions and other problems you need to use Cursorloader. They handle multiple things for you and make sure cursors are slick.
Therefore you need Content Providers.
The initial question is not answered yet thought. i don't know whats best practise for the number or content providers & tables. but within the .query method you check the URI id. you can test if the uri id has a specific value and build your query that way.
99% of Android applications do not need content providers.
Content providers have one primary use: inter-process communication. If you are:
expecting other developers to access your content providers, or
are integrating to Android in places that require a content provider (e.g., search suggestions for the Quick Search Box)
then, and only then, do you implement a content provider.
Otherwise, all you are doing is adding overhead to your application and making your code more difficult to maintain.
So, if your application is one of the 99% that does not need content providers, just get rid of the one you have and access your content by some other means (e.g., SQLiteDatabase).

Parse JSON response from Google Maps page

I'm trying to find the best way of parsing the response from a "normal" (i.e. not using the API) Google Maps page in my java code.
Reason: I want to submit a query string requesting a listing (be it hotels, restaurants etc.) and then parse the JSON that comes back. I had looked into using the Google Maps API, but it doesn't seem to cover what I want to do, as this type of URL:
http://maps.google.de/maps/geo?q=address&output=xml&oe=utf8&sensor=false&key=...
is OK but this isn't:
http://maps.google.de/maps/geo?q=address+hotels&output=xml&oe=utf8&sensor=false&key=...
(due to the "+hotels" term). So I think the only option is to use a google maps response e.g.
http://maps.google.de/maps?q=address+hotels
and parse the JSON information that is included at the end. Does anyone have some hints as to how best accomplish this?
You should first make absolutely sure that the API doesn't support what you need. Checking the docs and maybe even reaching a real Googler might pay off. It strikes me as odd that their API wouldn't support something as simple as adding in another term.
If you're forced to do it the "hard way", there are two main steps:
1) Find and learn a JSON parsing library for Java. I can recommend Jackson -- fast, sturdy, and just released a version 1.0.0.
2) Teach your code to understand the spec the Google uses in their response. This is by far the most challenging part. My apologies, but I know nothing about Google's spec in this area. If you can find official docs, that's best. Or find unofficial docs published by someone else who had to do similar work. Otherwise, you may have to "reverse engineer".
Re. the google api docs: it does seem that what you're trying to do goes against the intention of Google to make their product (= a map) available to you, the developer, for your custom enhancement (by adding business outlet information or whatever). There's plenty of stuff on the Google maps API site describing this. But to parse their data (coming out of their database) and to display it independently of their product would seem to be rather different: section 10.12 of the terms explicitly cover this:
...code.google.com/intl/de/apis/maps/terms.html
However, there are apps out there (the "Around Me" iPhone app, for example) that seem to do just that: there might be a special arrangement between Google and Apple in that regard.
EDIT: alternatively you could look at this problem another way and use the Google Base API feed, since this allows you to build query strings specifying resource, distance, location etc. - i.e. it returns the data you require without using the Maps API (which you don't need anyway, given your description).

Categories