1

我通过将纬度和经度值传递给以下 URL 来获取街道、城市和国家/地区的详细信息:http://maps.google.com/maps/geo?q="+la+","+lo;. 但是,这突然停止工作,因为我现在得到返回的状态代码 610 而不是 200。我用谷歌搜索并发现 Google 已弃用 V3 版本的旧版本,建议使用更新到此版本。新的 URL 将是这样的;

http://maps.googleapis.com/maps/api/geocode/json?latlng=25.34041,-55.489864&sensor=false

但是,我完全迷失了如何使用这个?什么是 Google API 密钥?我应该从哪里获得这个。早些时候我使用上述 URL 并将以下内容导入到我的项目中:

import org.json.me.JSONArray;
import org.json.me.JSONObject;

请帮助如何进行此操作?

4

1 回答 1

1

您正在请求正确的 URL,但您的 latlong 值可能无效。我请求网址:

http://maps.googleapis.com/maps/api/geocode/json?latlng=25.34041,-55.489864&sensor=false

结果。

{
   "results" : [],
   "status" : "ZERO_RESULTS"
}

使用不同的 latlong 但相同的 URL 请求:

http://maps.googleapis.com/maps/api/geocode/xml?latlng=51.962146,7.602304&sensor=false"



{
   "results" : [
      {
         "address_components" : [
            {
               "long_name" : "Rishon-Le-Zion-Ring",
               "short_name" : "K6",
               "types" : [ "route" ]
            },
            {
               "long_name" : "Münster",
               "short_name" : "Münster",
               "types" : [ "locality", "political" ]
            },
            {
               "long_name" : "Münster",
               "short_name" : "Münster",
               "types" : [ "administrative_area_level_2", "political" ]
            },
            {
               "long_name" : "North Rhine-Westphalia",
               "short_name" : "NRW",
               "types" : [ "administrative_area_level_1", "political" ]
            },
            {
               "long_name" : "Germany",
               "short_name" : "DE",
               "types" : [ "country", "political" ]
            },
            {
               "long_name" : "48149",
               "short_name" : "48149",
               "types" : [ "postal_code" ]
            }
         ],
         "formatted_address" : "Rishon-Le-Zion-Ring, 48149 Münster, Germany",
         "geometry" : {
            "bounds" : {
               "northeast" : {
                  "lat" : 51.96354080,
                  "lng" : 7.602404200000001
               },
               "southwest" : {
                  "lat" : 51.96109890,
                  "lng" : 7.601790299999998
               }
            },
            "location" : {
               "lat" : 51.96233620,
               "lng" : 7.602270099999999
            },
            "location_type" : "APPROXIMATE",
            "viewport" : {
               "northeast" : {
                  "lat" : 51.96366883029150,
                  "lng" : 7.603446230291501
               },
               "southwest" : {
                  "lat" : 51.96097086970850,
                  "lng" : 7.600748269708497
               }
            }
         },
         "types" : [ "route" ]
      },
      {
         "address_components" : [
            {
               "long_name" : "48149",
               "short_name" : "48149",
               "types" : [ "postal_code" ]
            },
            {
               "long_name" : "Münster",
               "short_name" : "Münster",
               "types" : [ "locality", "political" ]
            },
            {
               "long_name" : "Münster",
               "short_name" : "Münster",
               "types" : [ "administrative_area_level_3", "political" ]
            },
            {
               "long_name" : "Münster",
               "short_name" : "Münster",
               "types" : [ "administrative_area_level_2", "political" ]
            },
            {
               "long_name" : "North Rhine-Westphalia",
               "short_name" : "NRW",
               "types" : [ "administrative_area_level_1", "political" ]
            },
            {
               "long_name" : "Germany",
               "short_name" : "DE",
               "types" : [ "country", "political" ]
            }
         ],
         "formatted_address" : "48149 Münster, Germany",
         "geometry" : {
            "bounds" : {
               "northeast" : {
                  "lat" : 51.9846220,
                  "lng" : 7.6245910
               },
               "southwest" : {
                  "lat" : 51.9381030,
                  "lng" : 7.57505310
               }
            },
            "location" : {
               "lat" : 51.96236820,
               "lng" : 7.595598700000001
            },
            "location_type" : "APPROXIMATE",
            "viewport" : {
               "northeast" : {
                  "lat" : 51.9846220,
                  "lng" : 7.6245910
               },
               "southwest" : {
                  "lat" : 51.9381030,
                  "lng" : 7.57505310
               }
            }
         },
         "types" : [ "postal_code" ]
      },
      {
         "address_components" : [
            {
               "long_name" : "Münster",
               "short_name" : "Münster",
               "types" : [ "locality", "political" ]
            },
            {
               "long_name" : "Münster",
               "short_name" : "Münster",
               "types" : [ "administrative_area_level_2", "political" ]
            },
            {
               "long_name" : "North Rhine-Westphalia",
               "short_name" : "NRW",
               "types" : [ "administrative_area_level_1", "political" ]
            },
            {
               "long_name" : "Germany",
               "short_name" : "DE",
               "types" : [ "country", "political" ]
            }
         ],
         "formatted_address" : "Münster, Germany",
         "geometry" : {
            "bounds" : {
               "northeast" : {
                  "lat" : 52.06001970,
                  "lng" : 7.774361699999999
               },
               "southwest" : {
                  "lat" : 51.84015110000001,
                  "lng" : 7.473832599999999
               }
            },
            "location" : {
               "lat" : 51.96066490,
               "lng" : 7.62613470
            },
            "location_type" : "APPROXIMATE",
            "viewport" : {
               "northeast" : {
                  "lat" : 52.06001970,
                  "lng" : 7.774361699999999
               },
               "southwest" : {
                  "lat" : 51.84015110000001,
                  "lng" : 7.473832599999999
               }
            }
         },
         "types" : [ "locality", "political" ]
      },
      {
         "address_components" : [
            {
               "long_name" : "Münster",
               "short_name" : "Münster",
               "types" : [ "administrative_area_level_2", "political" ]
            },
            {
               "long_name" : "North Rhine-Westphalia",
               "short_name" : "NRW",
               "types" : [ "administrative_area_level_1", "political" ]
            },
            {
               "long_name" : "Germany",
               "short_name" : "DE",
               "types" : [ "country", "political" ]
            }
         ],
         "formatted_address" : "Münster, Germany",
         "geometry" : {
            "bounds" : {
               "northeast" : {
                  "lat" : 52.47498539999999,
                  "lng" : 8.320101899999999
               },
               "southwest" : {
                  "lat" : 51.48078280,
                  "lng" : 6.386867199999999
               }
            },
            "location" : {
               "lat" : 51.94711969999999,
               "lng" : 7.584531999999999
            },
            "location_type" : "APPROXIMATE",
            "viewport" : {
               "northeast" : {
                  "lat" : 52.47498539999999,
                  "lng" : 8.320101899999999
               },
               "southwest" : {
                  "lat" : 51.48078280,
                  "lng" : 6.386867199999999
               }
            }
         },
         "types" : [ "administrative_area_level_2", "political" ]
      },
      {
         "address_components" : [
            {
               "long_name" : "North Rhine-Westphalia",
               "short_name" : "NRW",
               "types" : [ "administrative_area_level_1", "political" ]
            },
            {
               "long_name" : "Germany",
               "short_name" : "DE",
               "types" : [ "country", "political" ]
            }
         ],
         "formatted_address" : "North Rhine-Westphalia, Germany",
         "geometry" : {
            "bounds" : {
               "northeast" : {
                  "lat" : 52.53146959999999,
                  "lng" : 9.461634900000002
               },
               "southwest" : {
                  "lat" : 50.3227010,
                  "lng" : 5.86634250
               }
            },
            "location" : {
               "lat" : 51.43323669999999,
               "lng" : 7.661593799999999
            },
            "location_type" : "APPROXIMATE",
            "viewport" : {
               "northeast" : {
                  "lat" : 52.53146959999999,
                  "lng" : 9.461634900000002
               },
               "southwest" : {
                  "lat" : 50.3227010,
                  "lng" : 5.86634250
               }
            }
         },
         "types" : [ "administrative_area_level_1", "political" ]
      },
      {
         "address_components" : [
            {
               "long_name" : "Germany",
               "short_name" : "DE",
               "types" : [ "country", "political" ]
            }
         ],
         "formatted_address" : "Germany",
         "geometry" : {
            "bounds" : {
               "northeast" : {
                  "lat" : 55.0583470,
                  "lng" : 15.04189620
               },
               "southwest" : {
                  "lat" : 47.27011150,
                  "lng" : 5.86634250
               }
            },
            "location" : {
               "lat" : 51.1656910,
               "lng" : 10.4515260
            },
            "location_type" : "APPROXIMATE",
            "viewport" : {
               "northeast" : {
                  "lat" : 55.0583470,
                  "lng" : 15.04189620
               },
               "southwest" : {
                  "lat" : 47.27011150,
                  "lng" : 5.86634250
               }
            }
         },
         "types" : [ "country", "political" ]
      }
   ],
   "status" : "OK"
}
于 2013-03-18T09:01:16.200 回答