/** * 百度接口
* 通过用户ip获取用户所在地
* @param userIp
* @return
*/
public static String getAddressByBD2(String strIP) {
try {
URL url = new URL(“http://opendata.baidu.com/api.php?query=” + strIP+"&co=&resource_id=6006&t=1433920989928&ie=utf8&oe=utf-8&format=json");;
URLConnection conn = url.openConnection();
BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream(), “utf-8”));
String line = null;
StringBuffer result = new StringBuffer();
while ((line = reader.readLine()) != null) {
result.append(line);
}
reader.close();
JSONObject jsStr = new JSONObject(result.toString());
JSONArray jsData = (JSONArray) jsStr.get(“data”);
JSONObject data= (JSONObject) jsData.get(0);//位置
return (String) data.get(“location”);
} catch (IOException e) {
return “读取失败”;
}
}

运行效果图:
百度接口通过ip获取用户所在地

网址:https://blog.csdn.net/ixiaoyang/article/details/73556701
详情请参考:http://matools.com/ip

相关文章:

  • 2021-11-29
  • 2022-01-19
  • 2022-02-03
  • 2021-07-12
  • 2021-10-09
  • 2021-11-08
猜你喜欢
  • 2021-11-25
  • 2021-12-04
  • 2021-11-22
  • 2021-07-26
  • 2021-11-03
  • 2021-06-03
  • 2022-01-10
相关资源
相似解决方案