2

Application to implement:

User is prompted to input his source location, after that user is prompted to input his destination location. After completion, a route will appear between source and destination.

Implemented so far

  • Splash Screen with 500ms delay
  • After 500ms user is shifted to MainActivity
  • Here a user is prompted to enter his current location in a text box.
  • As user enters his source, a marker appears on google maps

    About Textbox: The textbox I am using is a place autocomplete from Places API from google itself. This widget at any length of input shows specific place hints relative to the input. I am basically using the fragment implementation of this autocomplete textbox.

    Problem: Now the problem I am facing is that I want my textbox that was inputting source should now input destination. What should i do change the input type?

    Code:

    .xml file

    <fragment
        android:id="@+id/place_autocomplete_fragment"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:name="com.google.android.gms.location.places.ui.PlaceAutocompleteFragment" />
    
    <fragment xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:map="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/map"
        android:name="com.google.android.gms.maps.SupportMapFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context="com.mazik.ahmed.androidappontheway.MapsActivity" />
    

    .java file

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_maps);
        SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
                .findFragmentById(R.id.map);
        mapFragment.getMapAsync(this);
    
        PlaceAutocompleteFragment autocompleteFragment = (PlaceAutocompleteFragment)
                getFragmentManager().findFragmentById(R.id.place_autocomplete_fragment);
    
        autocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() {
            @Override
            public void onPlaceSelected(Place place) {
                LatLng latlng = new LatLng(place.getLatLng().latitude, place.getLatLng().longitude);
                mMap.addMarker(new MarkerOptions().position(latlng).title(place.getName().toString())
                        .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_VIOLET)));
            }
    
            @Override
            public void onError(Status status) { }
        });
    

    What I want is that the autocomplete widget prompt for a re-input after assuring the source has been selected.

  • pRaNaY
    • 24,642
    • 24
    • 96
    • 146
    Martin Gardener
    • 1,001
    • 8
    • 14
    • 1
      For proper implementation you should use two autocomplete textview.One workaround I can suggest is to keep an integer variable. If it is 0 then pick the place's latlong and set it as source and increment the variable.on next pick check the value of variable and if it is 1 set that lat long for destination. – Vivek Mishra Feb 22 '16 at 12:28
    • See [this](http://stackoverflow.com/questions/34416817/how-to-implement-placeautocompletefragment-and-placeautocompleteactivity-to-get) may help you. – pRaNaY Feb 22 '16 at 12:28
    • @VivekMishra i exactly thought of the same thing that you are recommending but it seems to be a hard coded way, hopefully there can be easier alternatives? :p – Martin Gardener Feb 22 '16 at 12:32
    • then you have to use 2 auto complete textview. you can't normally update two markers with one autocomplete – Vivek Mishra Feb 22 '16 at 12:34
    • is it possible that if i have 2 autocomplete textview, i can show 1 at a time and if i am done with the first one, i want the second one to take its place? – Martin Gardener Feb 22 '16 at 12:39

    0 Answers0