【问题标题】:Yandex API geocodeYandex API 地理编码
【发布时间】:2016-08-31 05:57:09
【问题描述】:

我正在尝试使用 Yandex 地理编码接收地址坐标。为了开始,我直接创建了一个查询,就像这里描述的那样https://tech.yandex.ru/maps/doc/geocoder/desc/concepts/input_params-docpage/

但是,它会响应 uri 不正确。我发现,这是因为 uri 包含俄语字母。我尝试使用 URLEncoder 修复它,但没有任何改变。将不胜感激任何形式的帮助。

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) {}
    }
}

线程“main”java.lang.IllegalArgumentException 中的异常:无效 uri 'https://geocode-maps.yandex.ru/1.x/?geocode=Санкт-Петербург':无效查询

【问题讨论】:

    标签: java encoding yandex


    【解决方案1】:

    您实际上并未对字符串进行编码。

    请尝试

    address = URLEncoder.encode(... 
    

    【讨论】:

    • ohhh :) 谢谢,有帮助
    猜你喜欢
    • 2015-05-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多