NutzCN Logo
问答 调用高德地图web服务将百度地图经纬度转化为高德地图经纬度失败
发布于 2250天前 作者 15868140584 2616 次浏览 复制 上一个帖子 下一个帖子
标签:

String lng = "121.506377"; // 经度
String lat = "31.245105"; // 纬度

    try {
       //URL url = new URL(" https://restapi.amap.com/v3/assistant/coordinate/convert?key=a910275072f1f2ad767b56fc9d0a0a56&locations="+lng+","+lat+"&coordsys=baidu");

       URL url = new URL("https://restapi.amap.com/v3/assistant/coordinate/convert?locations=116.481499,39.990475&coordsys=baidu&output=json&key=a910275072f1f2ad767b56fc9d0a0a56 ");

       URLConnection connection = url.openConnection();
       connection.setDoOutput(true);
       OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream(), "utf-8");
       out.flush();
       out.close();

       String sCurrentLine = "";
       String sTotalString = "";
       InputStream l_urlStream;
       l_urlStream = connection.getInputStream();
       BufferedReader l_reader = new BufferedReader(new InputStreamReader(l_urlStream));
       while ((sCurrentLine = l_reader.readLine()) != null) {

         if (!sCurrentLine.equals(""))
          sTotalString += sCurrentLine;
         }

       System.out.println(sTotalString);

} catch (Exception e) {
e.printStackTrace();
}

}

显示
{"status":"0","info":"MISSING_REQUIRED_PARAMS","infocode":"20001"}

但是我参数都 配上了 并且链接在浏览器中直接打开是成功的
{"status":"1","info":"ok","infocode":"10000","locations":"116.4748955248,39.984717169345"}

5 回复

请问有人知道什么原因吗?

你的URL多了空格呢

一行就能写完啦

        Response resp = Http.get("https://restapi.amap.com/v3/assistant/coordinate/convert?locations=116.481499,39.990475&coordsys=baidu&output=json&key=a910275072f1f2ad767b56fc9d0a0a56");
        String cnt = resp.getContent();
        NutMap re = Json.fromJson(NutMap.class, cnt);

后面两行是送你的, 转map方便操作

楼主解决了吗?同遇到这个问题

@hppyyung 报一样的错误?

添加回复
请先登陆
回到顶部