Good Evening,
I have been trying to implement a simple Android(tm) application that utilizes Google Places(tm) API to determine local points of interest (such as restaurants and hotels), however I have been having quite a lot of trouble determining how to actually get started.
Resources I have already employed are as follows:
-The Google Places(tm) documentation
-An Android(tm) development blog hosted by Brain Buikema
-The Android(tm) developer documentation on asynchronous tasks
-Various other stackoverflow postings from individuals in similar circumstances
I was simply hoping for some guidance so that anyone in my situation could simply find this post and maybe then be forwarded to some extremely insightful resources.
Further, I feel that using Google searches to find resources is somewhat inefficient, are there other databases out there that programmers frequently utilize of which I am not aware? Any recommended literature?
TL;DR...
-I'm looking for some definitive guides for using the Places API, working with JSON objects and networking on the Android(tm) platform.
-I was hoping to be redirected to some useful sources others have found in the past.
-I have included my Main.java file below simply to provide context - I am not looking for answers :)
Code for the Main.java class that implements the Places API functionality:
Button food = (Button) findViewById(R.id.button14);
food.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v)
{
type = "restaurant";
//Constructs the urlString
if(useCurr)
urlString = stringConstructor(myKey, lat, lon, radius, sensor, type);
else
{
//Here, you must update the lat and lon values according to the location input by the user
urlString = stringConstructor(myKey, lat, lon, radius, sensor, type);
}
//DO HTTPS REQUEST HERE
urlString = "https://maps.googleapis.com/maps/api/place/search/json?location=-33.8670522,151.1957362&radius=500&types=food&name=harbour&sensor=false&key=AIzaSyAp24M3GU9V3kWrrezye8CyUrhtpToUhrs";
Results res = new Results();
JSONArray json = res.doInBackground(urlString);
System.out.println(json);
}
});
Code for the Result class that handles the Asynchronous task:
private class Results extends AsyncTask<String, Integer, JSONArray>
{
protected JSONArray doInBackground(String...params)
{
JSONArray output = null;
try
{
try
{
url = new URL(params[0]);
}
catch(MalformedURLException e)
{
System.out.println("URL formed incorrectly! (" + e + ")");
}
output = (JSONArray) url.getContent();
}
catch(Exception e)
{
System.out.println("Exception: " + e);
}
return output;
}
}
Currently receiveing an android.os.NetworkOnMainThreatException whenever I click on the "Food" button (described above) in the emulator.
Any advice is greatly welcomed, I am trying to build a really solid foundation on the Android platform.