利用google地圖擷取位置經緯度坐标的方法
public static void main(String[] args) throws UnsupportedEncodingException {
String address = URLEncoder.encode("北京 香山公園","UTF-8");
String url = "http://maps.google.cn/maps/geo?q="+address+"&output=csv&oe=utf8\\&sensor=true_or_false& key=ABQIAAAAqaGKijD7euSpqDeVsNA85xTT3OL8VXjPlPTFW7n7OgOFwXoSnxT7IP1pHznaiGwWMvsEq_SkxvESLw";
String content = Spider.getContent(url);
String[] info = content.split(",");
System.out.println(info[2]+","+info[3]);
}
一下為改過後的代碼
public static void main(String[] args) throws UnsupportedEncodingException {
String address = URLEncoder.encode("北京 香山公園","UTF-8");
String url = "http://maps.google.cn/maps/geo?q="+address+"&output=json&ie=utf8";
String content = Spider.getContent(url);
String[] info = content.split(",");
System.out.println(info[2]+","+info[3]);
}
http://maps.google.cn/maps/geo?q=南京市&output=json&ie=utf8
{
"name": "南京市",
"Status": {
"code": 200,
"request": "geocode"
},
"Placemark": [ {
"id": "p1",
"address": "中國江蘇省南京市",
"AddressDetails": {
"Accuracy" : 4,
"Country" : {
"AdministrativeArea" : {
"AdministrativeAreaName" : "江蘇省",
"Locality" : {
"LocalityName" : "南京市"
}
},
"CountryName" : "中國",
"CountryNameCode" : "CN"
}
},
"ExtendedData": {
"LatLonBox": {
"north": 32.3940135,
"south": 31.8045247,
"east": 119.0501690,
"west": 118.4253323
}
},
"Point": {
"coordinates": [ 118.7968770, 32.0602550, 0 ]
}
} ]
}