我编写了以下代码来获取地址的坐标
package test;
import java.net.HttpURLConnection; import java.net.URL; import sun.net.www.content.text.PlainTextInputStream;
公共课a {
public static void main(String[] arg) throws Exception{
String address = "台北市信義路五段七號101樓";
// 查詢經緯度
String output = "csv";
String key = "";
String url = "http://maps.google.com/maps/geo?q=台北市信義路五段七號101樓&output=csv&key=ABQIAAAAXDq__hWKi9eMCwnn7LrMCxT2yXp_ZAY8_ufC3CFXhHIE1NvwkxSnSVp_Xlsd4Ph5iyMua7PE5E0x_A";
URL iurl = new URL(url);
HttpURLConnection uc = (HttpURLConnection)iurl.openConnection();
uc.connect();
Object content = uc.getContent();
// 讀取結果
PlainTextInputStream sr = (PlainTextInputStream)content;
byte[] buf = new byte[2000];
// 解析 200,8,25.033408,121.564099 (HTTP status code, accuracy, latitude, longitude)
sr.read(buf);
String[] tmpArray = new String(buf, "UTF-8").split(",");
String latitude = tmpArray[2];
String longitude = tmpArray[3];
}
}
问题是我在内容中获得了400个代码 我把网址放在浏览器中,它返回200.
有没有办法在无浏览器的情况下做到这一点?