I dont know how to fetch result, only of nearby bus stops.I tried to go through place picker documentation for help.But it shows all the nearby places ,if i only need bus stops what to do.It returns all nearby places how to get only what i want
import android.Manifest;
import android.content.Intent;
import android.content.IntentSender;
import android.content.pm.PackageManager;
import android.location.Location;
import com.google.android.gms.common.GooglePlayServicesNotAvailableException;
import com.google.android.gms.common.GooglePlayServicesRepairableException;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.widget.Toast;
import com.google.android.gms.location.places.Place;
import com.google.android.gms.location.places.ui.PlacePicker;
import com.google.android.gms.maps.model.LatLngBounds;
import transportation.lumiumdesign.com.transportation.R;
/**
*
* It contains a place picker to detect current location and nearby bus stops to it.
*/
public class CurrentLocMap extends FragmentActivity {
int PLACE_PICKER_REQUEST = 1;//Predefined req_code
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.current_loc_map);
PlacePicker.IntentBuilder builder = new PlacePicker.IntentBuilder();
/** Intent Builder will set current location of deviceif not provided
**/
try {
startActivityForResult(builder.build(this), PLACE_PICKER_REQUEST);
} catch (GooglePlayServicesRepairableException e) {
e.printStackTrace();
} catch (GooglePlayServicesNotAvailableException e) {
e.printStackTrace();
}
}
//onActivityResult will launch place picker
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == PLACE_PICKER_REQUEST) {
if (resultCode == RESULT_OK) {
Place place = PlacePicker.getPlace(this, data);
String toastMsg = String.format("Place: %s", place.getName());
Toast.makeText(this, toastMsg, Toast.LENGTH_LONG).show();
}
}
}
}
Unfortunately, filtering can't be done even when extending the Place Picker Class as what nowavewater have tested.
You can also follow these two open issues for updates shared by sidecarcat:
https://code.google.com/p/gmaps-api-issues/issues/detail?id=8484
https://code.google.com/p/gmaps-api-issues/issues/detail?id=8565
But you can try using, place autocomplete
The autocomplete service in the Google Places API for Android returns place predictions in response to user search queries. As the user types, the autocomplete service returns suggestions for places such as businesses, addresses and points of interest.
You can set the autocomplete widget to bias results to a specific geographic region, and/or filter the results to one or more place types.
To filter autocomplete results to a specific place type, call
AutocompleteFilter.Builder
to create a newAutocompleteFilter
, callingsetTypeFilter()
to set the filter to use. Then, pass the filter to a fragment or intent.
Code Sample :
AutocompleteFilter typeFilter = new AutocompleteFilter.Builder()
.setTypeFilter(AutocompleteFilter.TYPE_FILTER_ADDRESS)
.build();
Intent intent =
new PlaceAutocomplete.IntentBuilder(PlaceAutocomplete.MODE_FULLSCREEN)
.setFilter(typeFilter)
.build(this);