Getting Google Places result which have phone numbers
I am building an application where we can find the nearest stores which
has phone number registered with google places. I am using a fairly known
set of codes for this available in this address also -
http://www.androidhive.info/2012/08/android-working-with-google-places-and-maps-tutorial/.
Now when I am running the downloaded code as it is (only including
"rankby" instead of "radius") the is running fine. But for filtering the
result with phone number I added an 'if' in it. and then it is not
returning any result at all. And I found that when I am calling the
GooglePlaces.getPlaceDetails(reference). from the MainActivity it is
throwing an exception. but from SinglePlaceActivity it is working fine.
The second problem I am also facing is if I change the MainActivity
(without implementing if clause) to some other activity and call that from
new MainActivity without passing anything it is giving an error
subsequently the application shuts down. I think these two problems are
interconnected, so I am asking together.
Thanks in advance...
required part of My MainActivity.java after alteration
protected String doInBackground(String... args) {
// creating Places class object
googlePlaces = new GooglePlaces();
try {
String types = "store"; // Listing places only ambulances
// get nearest places
nearPlaces = googlePlaces.search(gps.getLatitude(),
gps.getLongitude(), types);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
protected void onPostExecute(String file_url) {
// dismiss the dialog after getting all products
pDialog.dismiss();
// updating UI from Background Thread
runOnUiThread(new Runnable() {
public void run() {
/**
* Updating parsed Places into LISTVIEW
* */
// Get json response status
String status = nearPlaces.status;
// Check for all possible status
if(status.equals("OK")){
// Successfully got places details
if (nearPlaces.results != null) {
// loop through each place
googlePlaceDetails = new GooglePlaces();
for (Place p : nearPlaces.results) {
try {
PlaceID = p.reference;
placeDetails =
googlePlaceDetails.getPlaceDetails(PlaceID);
txtPhone =
placeDetails.result.formatted_phone_number;
} catch (Exception e)
{
}
if (txtPhone!=null){
HashMap<String, String> map = new HashMap<String,
String>();
map.put(KEY_REFERENCE, p.reference);
map.put(KEY_NAME, p.name);
placesListItems.add(map);
}
}
ListAdapter adapter = new SimpleAdapter(MainActivity.this,
placesListItems,
R.layout.list_item,
new String[] { KEY_REFERENCE, KEY_NAME}, new int[] {
R.id.reference, R.id.name });
lv.setAdapter(adapter);
}
}
else if(status.equals("ZERO_RESULTS")){
// Zero results found
alert.showAlertDialog(MainActivity.this, "Near Places",
"Sorry no places found. Try to change the
types of places",
false);
}
else if(status.equals("UNKNOWN_ERROR"))
{
alert.showAlertDialog(MainActivity.this, "Places Error",
"Sorry unknown error occured.",
false);
}
else if(status.equals("OVER_QUERY_LIMIT"))
{
alert.showAlertDialog(MainActivity.this, "Places Error",
"Sorry query limit to google places is reached",
false);
}
else if(status.equals("REQUEST_DENIED"))
{
alert.showAlertDialog(MainActivity.this, "Places Error",
"Sorry error occured. Request is denied",
false);
}
else if(status.equals("INVALID_REQUEST"))
{
alert.showAlertDialog(MainActivity.this, "Places Error",
"Sorry error occured. Invalid Request",
false);
}
else
{
alert.showAlertDialog(MainActivity.this, "Places Error",
"Sorry error occured.",
false);
}
}
});
}
}
I haven't altered my GooglePlaces.java file, and as this is a very well
known code I am not uploading it. if anyone can help me out it will be of
immense help for me...
Again, thanks in advance.
No comments:
Post a Comment