0

Code to create URL:

EditText editText = (EditText) findViewById(R.id.editText);

String Destin = editText.getText().toString();


StringBuilder googlePlacesUrl = new StringBuilder("https://maps.googleapis.com/maps/api/place/textsearch/json?");
    //googlePlacesUrl.append(name);
    googlePlacesUrl.append("key=myKey&query=");
    googlePlacesUrl.append(name);

=========================


Logs on Fail: java.io.FileNotFoundException: https://maps.googleapis.com/maps/api/place/textsearch/json?key=myKey&query=Place_name street

Also,succefussly getting location for:name=place_name i.e. with no spaces https://maps.googleapis.com/maps/api/place/textsearch/json?key=myKey&query=Place_name

AndrewR
  • 10,759
  • 10
  • 45
  • 56
lokesh
  • 109
  • 1
  • 1
  • 9

3 Answers3

3

Use UrlEncoder.encode(name) to encode the query string. This will replace the space with %20.

(see also: https://stackoverflow.com/a/3286128/2994)

Community
  • 1
  • 1
AndrewR
  • 10,759
  • 10
  • 45
  • 56
1

Download Sample project of Google Place API from Google Place API Sample

...Jalsa kar bhai

Tecksky Android
  • 133
  • 3
  • 14
0

Space is not work in url while execute request whether it is get or post. If url contain space then it is necessary to encode space in unicode then and only it works. For that

If Place Name has space then it should be replace with '%20' Eg. Place Name : united kingdom then

placeName = etPlaceName.getTExt().toString();
placeName = placeName.replace(" ","%20");

Use this place name in url to get result...........

Tecksky Android
  • 133
  • 3
  • 14
  • I have tried this,but for some reasons replace(" ","%20"); is not working...it doesn't replaces spaces – lokesh Nov 09 '16 at 11:06