Sunny
Sunny

Reputation: 14828

converting a URL

I have a method

String Address=search.getText().toString();

private String getAddressUrl() {
     String mapUrl="http://maps.googleapis.com/maps/api/geocode/json?";
     String add=Address; //Address is a String input by the user  
     String baseUrl1=mapUrl+"address="+add+"&sensor=true";
return baseUrl1;
}

If I input the string like "170 william street New York, NY" I am getting illegal character at query error because it contains spaces.

Is there any method to insert %20 for spaces in Address string

Upvotes: 0

Views: 254

Answers (3)

Andy
Andy

Reputation: 11

Oops, thought this was .Net for some reason.

Upvotes: 0

Eugen Martynov
Eugen Martynov

Reputation: 20140

You should use class UrlEncoder

Upvotes: 1

kabuko
kabuko

Reputation: 36302

Look at Uri.encode(String).

String add=Uri.encode(Address);

Upvotes: 5

Related Questions