/**

* 获取指定IP对应的经纬度(为空返回当前机器经纬度)





* @param ip


* @return


*/


public static String[] getIPXY(String ip) {

String ak = "百度申请的Key";


if (null == ip) {


ip = "";


}

try {

URL url = new URL("http://api.map.baidu.com/location/ip?ak=" + ak


+ "&ip=" + ip + "&coor=bd09ll");


InputStream inputStream = url.openStream();


InputStreamReader inputReader = new InputStreamReader(inputStream);


BufferedReader reader = new BufferedReader(inputReader);


StringBuffer sb = new StringBuffer();


String str;


do {


str = reader.readLine();


sb.append(str);


} while (null != str);

str = sb.toString();


if (null == str || str.isEmpty()) {


return null;


}

// 获取坐标位子


int index = str.indexOf("point");


int end = str.indexOf("}}", index);

if (index == -1 || end == -1) {


return null;


}

str = str.substring(index - 1, end + 1);


if (null == str || str.isEmpty()) {


return null;


}

String[] ss = str.split(":");


if (ss.length != 4) {


return null;


}

String x = ss[2].split(",")[0];


String y = ss[3];

x = x.substring(x.indexOf("\"") + 1, x.indexOf("\"", 1));


y = x.substring(y.indexOf("\"") + 1, y.indexOf("\"", 1));

return new String[] { x, y };

} catch (MalformedURLException e) {


e.printStackTrace();


} catch (IOException e) {


e.printStackTrace();


}

return null;


}

通过百度获取IP地址对应的经纬度的更多相关文章

  1. js获取IP地址方法总结_转

    js代码获取IP地址的方法,如何在js中取得客户端的IP地址.原文地址:js获取IP地址的三种方法 http://www.jbxue.com/article/11338.html 1,js取得IP地址 ...

  2. js获取IP地址多种方法实例教程

    js获取IP地址方法总结   js代码获取IP地址的方法,如何在js中取得客户端的IP地址.原文地址:js获取IP地址的三种方法 http://www.jbxue.com/article/11338. ...

  3. js获取IP地址方法总结

    js代码获取IP地址的方法,如何在js中取得客户端的IP地址.原文地址:js获取IP地址的三种方法 http://www.jbxue.com/article/11338.html 1,js取得IP地址 ...

  4. JAVA从本机获取IP地址

    JAVA从本机获取IP地址 论述: 此篇博客是在工作的时候,需要获得当前网络下面正确的ip地址,在网上查阅很多博客,网上一个比较普遍的说法是通过InetAddress.getLocalHost().g ...

  5. windows下获取IP地址的两种方法

    windows下获取IP地址的两种方法: 一种可以获取IPv4和IPv6,但是需要WSAStartup: 一种只能取到IPv4,但是不需要WSAStartup: 如下: 方法一:(可以获取IPv4和I ...

  6. 【PHP开发篇】一个统计客户端商机提交的获取IP地址

    1.对客服提交数据的ip地址记录. 获取ip地址的方法: public function getIP() { global $ip; if (getenv("HTTP_X_REAL_IP&q ...

  7. 获取 IP 地址

    package j2se.core.net.base; import java.net.InetAddress;import java.net.UnknownHostException; public ...

  8. iOS 获取IP地址

    一.获取本机IP地址 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 #import <ifadd ...

  9. Linux下Python获取IP地址

    <lnmp一键安装包>中需要获取ip地址,有2种情况:如果服务器只有私网地址没有公网地址,这个时候获取的IP(即私网地址)不能用来判断服务器的位置,于是取其网关地址用来判断服务器在国内还是 ...

随机推荐

  1. Android内存泄漏的各种原因详解

    转自:http://mobile.51cto.com/abased-406286.htm 1.资源对象没关闭造成的内存泄漏 描述: 资源性对象比如(Cursor,File文件等)往往都用了一些缓冲,我 ...

  2. 鼠标滑动判断与y轴的距离

     $(window).scroll(function(){                        var y = window.scrollY;//754到达                  ...

  3. 【转】数据库分页Java实现

    [转]数据库分页Java实现 MySQL分页 主要是MySQL数据库内置LIMIT函数 注意添加mysql的JAR包mysql-connector-java-5.1.13-bin.jar 在中小数据量 ...

  4. 使用第三方框架 Masonry 实现自动布局

    使用第三方框架 Masonry 实现自动布局 时间:2015-02-10 11:08:41      阅读:4595      评论:0      收藏:0      [点我收藏+] 标签: 由于前两 ...

  5. AlertView + Block 的使用

    AlertView的使用还是很频繁的,扁平化以后似乎也不是那么丑了,但是到现在为止官方还是在用Delegate来处理点击事件,很影响程序的可读性. 如果用Block那么就会一目了然.自己本来想写一个, ...

  6. TCP/IP-IP

    A contented mind is a perpetual feast. "知足长乐" 参考资料:TCP/IP入门经典 (第五版) TCP/IP详解 卷一:协议 一.简介 IP ...

  7. 打包静默安装参数(nsis,msi,InstallShield,InnoSetup)[转]

    有时我们在安装程序的时候,希望是静默安装的,不显示下一步下一步,这编访问来教大家如何来操作,现在常用的制作安装程序的软件有,  Microsoft Windows Installer  , Windo ...

  8. Extjs之rowEditing编辑状态时列不对齐

    Extjs在使用rowEditing的时候,会在每一列加上editor属性,表示当处于编辑状态时这一列的值是什么类型的,后突然发现在rowEditing处于编辑状态时每一列的宽度边框了,如果列数非常多 ...

  9. js Math函数

    1.丢弃小数部分,保留整数部分parseInt(5/2) 2.向上取整,有小数就整数部分加1 Math.ceil(5/2) 3,四舍五入. Math.round(5/2) 4,向下取整 Math.fl ...

  10. yii2源码学习笔记(二)

    yii\base\Object代码详解 <?php /** * @link http://www.yiiframework.com/ * @copyright Copyright (c) 200 ...