利用google地图获取位置经纬度坐标的方法

利用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 ]
    }
  } ]
}

 

posted @ 2013-02-26 12:53  清新每一天  阅读(916)  评论(0编辑  收藏  举报