下面我們舉例說明一下關於利用百度獲取IP地址經緯度的方法:
/**
* 獲取指定IP對應的經緯度(為空返回當前機器經緯度)
*
* @param ip
* @return
*/
public static String[] getIPXY(String ip) {
String ak =
if (null == ip) {
ip =
}
try {
URL url = new URL(
+
InputStream inputStream = url
InputStreamReader inputReader = new InputStreamReader(inputStream);
BufferedReader reader = new BufferedReader(inputReader);
StringBuffer sb = new StringBuffer();
String str;
do {
str = reader
sb
} while (null != str);
str = sb
if (null == str || str
return null;
}
// 獲取坐標位子
int index = str
int end = str
if (index ==
return null;
}
str = str
if (null == str || str
return null;
}
String[] ss = str
if (ss
return null;
}
String x = ss[
String y = ss[
x = x
y = x
return new String[] { x
} catch (MalformedURLException e) {
e
} catch (IOException e) {
e
}
return null;
}
From:http://tw.wingwit.com/Article/program/Java/hx/201311/26637.html