I am trying to receive coordinates for address using Yandex geocode. To get started I created a query directly like it is described here https://tech.yandex.ru/maps/doc/geocoder/desc/concepts/input_params-docpage/
However, it responds that uri is not correct. As I found out, it is because uri contains Russian letters. I tried to fix it using URLEncoder, but nothing changed. Will be grateful for any kind of help.
import com.sun.deploy.net.URLEncoder;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.methods.GetMethod;
public class Main {
public static void main(String[] args) {
String address = "Санкт-Петербург";
try {
URLEncoder.encode(address, "UTF-8");
} catch (Exception e) {
System.out.print("BAD");
}
System.out.println(address);
HttpClient client = new HttpClient();
String request = "https://geocode-maps.yandex.ru/1.x/?geocode=" + address;
GetMethod method = new GetMethod(request);
String Lat="",Long="";
try {
client.executeMethod(method);
String s = method.getResponseBodyAsString();
System.out.print(s);
} catch (Exception e) {}
}
}
Exception in thread "main" java.lang.IllegalArgumentException: Invalid uri 'https://geocode-maps.yandex.ru/1.x/?geocode=Санкт-Петербург': Invalid query