title: How to implement Google Map search by address location in fragment
body: <p>I am trying to create an app. I want to add search by address on google map in fragment Using the following code-</p>
  
  <pre><code>public class Search extends Fragment implements OnItemClickListener{
  
  private final String  TAG = this.getClass().getSimpleName();
  
  MainActivity main=null;
  PlacesTask placesTask = null ;
  DownloadTask downloadTask=null;
  LatLng latLng;
  GoogleMap mMap;
  Marker CurrentMarker,FindMarker;
  
  AutoCompleteTextView autoCompView=null;
  Button findbtn = null;
  private static final String PLACES_API_BASE = "https://maps.googleapis.com/maps/api/place";
  private static final String TYPE_AUTOCOMPLETE = "/autocomplete";
  private static final String OUT_JSON = "/json";
  
  //------------ make your specific key ------------
  private static final String API_KEY = "**************************************";
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
          Bundle savedInstanceState) {
  
      View view=inflater.inflate(R.layout.search, container,false);
      autoCompView = (AutoCompleteTextView) view.findViewById(R.id.editplace);
  
      autoCompView.setAdapter(new GooglePlacesAutocompleteAdapter(getActivity(), R.layout.list_item));
      autoCompView.setOnItemClickListener(this);
  
      findbtn  =(Button) view.findViewById(R.id.findbtn);
      findbtn.setOnClickListener(new OnClickListener() {
  
          @Override
          public void onClick(View v) {
              // TODO Auto-generated method stub
              String location = autoCompView.getText().toString();
              if(location!=null &amp;&amp; !location.equals("")){
                    new GeocoderTask().execute(location); 
              Log.e(TAG, "login button is clicked");
  
  
                  }
  
          }
      });
  
  
  
      return view;
  
     }
  
  private class GeocoderTask extends AsyncTask&lt;String, Void, List&lt;Address&gt;&gt;{
  
      @Override
      protected List&lt;Address&gt; doInBackground(String... locationName) {
          // TODO Auto-generated method stub
  
          Geocoder geocoder = new Geocoder(getActivity());
          List&lt;Address&gt; addresses = null;
  
          try {
              // Getting a maximum of 3 Address that matches the input text
              addresses = geocoder.getFromLocationName(locationName[0],3);
          } catch (IOException e) {
              e.printStackTrace();
          }
          return addresses;
      }
  
      protected void onPostExecute(List&lt;Address&gt;addresses) {
          if(addresses==null || addresses.size()==0){
              Toast.makeText(getActivity(), "No Location found", Toast.LENGTH_SHORT).show();
          }
  
          for(int i=0;i&lt;addresses.size();i++){
          Address address =  (Address)addresses.get(i);
          latLng = new LatLng(address.getLatitude(), address.getLongitude());
          String addressText = String.format("%s, %s",
          address.getMaxAddressLineIndex() &gt; 0 ? address.getAddressLine(0) : "",
          address.getCountryName());
          MarkerOptions markerOptions = new MarkerOptions();
          markerOptions.position(latLng);
          markerOptions.title("Find Location");
          markerOptions.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED));
  FindMarker=mMap.addMarker(markerOptions);
  
  
          CameraPosition cameraPosition = new CameraPosition.Builder().target(latLng).zoom(14).build();
          mMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
          double mLatitude=address.getLatitude();
          double mLongitude=address.getLongitude();
          StringBuilder sb = new StringBuilder("https://maps.googleapis.com/maps/api/place/nearbysearch/json?");
          sb.append("location="+mLatitude+","+mLongitude);
          sb.append("&amp;radius=5000");
          sb.append("&amp;types=" + "liquor_store");
          sb.append("&amp;sensor=true");
          sb.append("&amp;key=********************************");
          Log.d("Map", "&lt;&gt;&lt;&gt;api: " + sb.toString());
  
          //query places with find location
          placesTask.execute(sb.toString());
  
          //for direction Route
          LatLng origin = CurrentMarker.getPosition();
         LatLng dest = FindMarker.getPosition();
  
          String url = getDirectionsUrl(origin, dest);
  
  
          // Start downloading json data from Google Directions API
          downloadTask.execute(url);
          Toast.makeText(getActivity(), " Location found", Toast.LENGTH_SHORT).show();
  
  
          }
  
      }       
  
   }
  
  @Override
  public void onResume() {
  
     super.onResume();
  
  
      getView().setFocusableInTouchMode(true);
      getView().requestFocus();
      getView().setOnKeyListener(new View.OnKeyListener() {
          @Override
          public boolean onKey(View v, int keyCode, KeyEvent event) {
  
              if (event.getAction() == KeyEvent.ACTION_UP &amp;&amp; keyCode == KeyEvent.KEYCODE_BACK){
                  if(getFragmentManager().getBackStackEntryCount() &gt; 0) {
                    getFragmentManager().popBackStack();
                  }
  
                  return true;
  
              }
  
              return false;
          }
      });
  }
  @Override
  public void onDestroyView() {
      super.onDestroyView();
      getActivity().getActionBar().setTitle("IQWINER");
  
  
  }
  
  @Override
  public void onItemClick(AdapterView adapterView, View view, int position,
          long id) {
      // TODO Auto-generated method stub
      String str = (String) adapterView.getItemAtPosition(position);
      Toast.makeText(getActivity(), str, Toast.LENGTH_SHORT).show();
  
  }
  
  public static ArrayList&lt;String&gt; autocomplete(String input) {
      ArrayList&lt;String&gt; resultList = null;
  
      HttpURLConnection conn = null;
      StringBuilder jsonResults = new StringBuilder();
      try {
          StringBuilder sb = new StringBuilder(PLACES_API_BASE + TYPE_AUTOCOMPLETE + OUT_JSON);
          sb.append("?key=" + API_KEY);
          sb.append("&amp;input=" + URLEncoder.encode(input, "utf8"));
  
          URL url = new URL(sb.toString());
  
          System.out.println("URL: "+url);
          conn = (HttpURLConnection) url.openConnection();
          InputStreamReader in = new InputStreamReader(conn.getInputStream());
  
          // Load the results into a StringBuilder
          int read;
          char[] buff = new char[1024];
          while ((read = in.read(buff)) != -1) {
              jsonResults.append(buff, 0, read);
          }
      } catch (MalformedURLException e) {
          //Log.e(LOG_TAG, "Error processing Places API URL", e);
          return resultList;
      } catch (IOException e) {
          //Log.e(LOG_TAG, "Error connecting to Places API", e);
          return resultList;
      } finally {
          if (conn != null) {
              conn.disconnect();
          }
      }
  
      try {
  
          // Create a JSON object hierarchy from the results
          JSONObject jsonObj = new JSONObject(jsonResults.toString());
          JSONArray predsJsonArray = jsonObj.getJSONArray("predictions");
  
          // Extract the Place descriptions from the results
          resultList = new ArrayList&lt;String&gt;(predsJsonArray.length());
          for (int i = 0; i &lt; predsJsonArray.length(); i++) {
  
              resultList.add(predsJsonArray.getJSONObject(i).getString("description"));
          }
      } catch (JSONException e) {
          //Log.e(LOG_TAG, "Cannot process JSON results", e);
      }
  
      return resultList;
  }
  
  class GooglePlacesAutocompleteAdapter extends ArrayAdapter&lt;String&gt; implements Filterable {
      private ArrayList&lt;String&gt; resultList;
  
      public GooglePlacesAutocompleteAdapter(Context context, int textViewResourceId) {
          super(context, textViewResourceId);
      }
  
  
  
      @Override
      public int getCount() {
          return resultList.size();
      }
  
      @Override
      public String getItem(int index) {
          return resultList.get(index);
      }
  
      @Override
      public Filter getFilter() {
          Filter filter = new Filter() {
              @Override
              protected FilterResults performFiltering(CharSequence constraint) {
                  FilterResults filterResults = new FilterResults();
                  if (constraint != null) {
                      // Retrieve the autocomplete results.
                      resultList = autocomplete(constraint.toString());
  
                      // Assign the data to the FilterResults
                      filterResults.values = resultList;
                      filterResults.count = resultList.size();
                  }
                  return filterResults;
              }
  
              @Override
              protected void publishResults(CharSequence constraint, FilterResults results) {
                  if (results != null &amp;&amp; results.count &gt; 0) {
                      notifyDataSetChanged();
                  } else {
                      notifyDataSetInvalidated();
                  }
              }
          };
          return filter;
      }
    }
  }
  </code></pre>
  
  <p>[enter error description here][2]</p>
  
  <p>how to implement search by address location on Google Map in fragment.Please tell me..</p>
  
  <p><a href="http://i.stack.imgur.com/xaRWF.png" rel="nofollow">enter error description here</a></p>