【发布时间】:2012-09-15 04:02:55
【问题描述】:
我正在使用 google geocoding api 来获取结果,但它返回“ZERO_RESULTS”。下面是代码
public class GeoCode {
public static void main(String[] args) throws Exception {
GeoCode.geocode("latlng=40.714224,-73.961452");
}
private static final String URL = "http://maps.googleapis.com/maps/api/geocode/json";
public static void geocode(String address) throws Exception {
URL url = new URL(URL + "?" + URLEncoder.encode(address, "UTF-8") + "&sensor=false");
URLConnection conn = url.openConnection();
ByteArrayOutputStream output = new ByteArrayOutputStream(1024);
IOUtils.copy(conn.getInputStream(), output);
output.close();
//JSONObject json = new JSONObject(output.toString());
System.out.println(output.toString());
}
}
当我在浏览器的地址栏上手动使用地址时,它会在浏览器上显示 json 结果。但是上面的代码实际上有什么问题,它在 json 中返回“ZERO_RESULTS”?
【问题讨论】:
标签: java google-maps-api-3 geocoding reverse-geocoding