1. 程式人生 > >根據經緯度根據谷歌地圖接口獲取到當前地址

根據經緯度根據谷歌地圖接口獲取到當前地址

component col 經緯度 ati Language pre googl _id .com

/*http://maps.google.com/maps/api/geocode/json?latlng=40.714224,-73.961452&sensor=true */

上面的訪問地址國內可能無法訪問,國內可以訪問以下地址

String url = "http://maps.google.cn/maps/api/geocode/json?latlng="+latitude+","+longitude+"&sensor=true&language=zh-CN";
//latitude 緯度 //longitude 經度   

例如:
http://maps.google.cn/maps/api/geocode/json?latlng=31.094668243086,121.21736204624&sensor=true&language=zh-CN

以下是返回的json數據


{
    "results": [
        {
            "address_components": [
                {
                    "long_name": "888",
                    "short_name": "888",
                    "types": [
                        "street_number"
                    ]
                },
                {
                    
"long_name": "林湖路", "short_name": "林湖路", "types": [ "route" ] }, { "long_name": "松江區", "short_name": "松江區", "types": [
"political", "sublocality", "sublocality_level_1" ] }, { "long_name": "上海市", "short_name": "上海市", "types": [ "locality", "political" ] }, { "long_name": "上海市", "short_name": "上海市", "types": [ "administrative_area_level_1", "political" ] }, { "long_name": "中國", "short_name": "CN", "types": [ "country", "political" ] } ], "formatted_address": "中國上海市松江區林湖路888號", "geometry": { "location": { "lat": 31.093379, "lng": 121.217555 }, "location_type": "ROOFTOP", "viewport": { "northeast": { "lat": 31.0947279802915, "lng": 121.2189039802915 }, "southwest": { "lat": 31.0920300197085, "lng": 121.2162060197085 } } }, "place_id": "ChIJ77t1mgr1sjUR8FQ6cZVYTAI", "types": [ "street_address" ] }, { "address_components": [ { "long_name": "松江區", "short_name": "松江區", "types": [ "political", "sublocality", "sublocality_level_1" ] }, { "long_name": "上海市", "short_name": "上海市", "types": [ "locality", "political" ] }, { "long_name": "上海市", "short_name": "上海市", "types": [ "administrative_area_level_1", "political" ] }, { "long_name": "中國", "short_name": "CN", "types": [ "country", "political" ] } ], "formatted_address": "中國上海市松江區", "geometry": { "bounds": { "northeast": { "lat": 31.1629344, "lng": 121.3723276 }, "southwest": { "lat": 30.8943398, "lng": 121.0248826 } }, "location": { "lat": 31.032243, "lng": 121.227747 }, "location_type": "APPROXIMATE", "viewport": { "northeast": { "lat": 31.1629344, "lng": 121.3723276 }, "southwest": { "lat": 30.8943398, "lng": 121.0248826 } } }, "place_id": "ChIJOzMSRxPzsjURTD7MqSppnco", "types": [ "political", "sublocality", "sublocality_level_1" ] }, { "address_components": [ { "long_name": "上海市", "short_name": "上海市", "types": [ "locality", "political" ] }, { "long_name": "上海市", "short_name": "上海市", "types": [ "administrative_area_level_1", "political" ] }, { "long_name": "中國", "short_name": "CN", "types": [ "country", "political" ] } ], "formatted_address": "中國上海市", "geometry": { "bounds": { "northeast": { "lat": 31.8727163, "lng": 122.2471487 }, "southwest": { "lat": 30.6755932, "lng": 120.8568046 } }, "location": { "lat": 31.2303904, "lng": 121.4737021 }, "location_type": "APPROXIMATE", "viewport": { "northeast": { "lat": 31.6688967, "lng": 122.1137989 }, "southwest": { "lat": 30.7798012, "lng": 120.8397067 } } }, "place_id": "ChIJMzz1sUBwsjURoWTDI5QSlQI", "types": [ "locality", "political" ] }, { "address_components": [ { "long_name": "上海市", "short_name": "上海市", "types": [ "administrative_area_level_1", "political" ] }, { "long_name": "中國", "short_name": "CN", "types": [ "country", "political" ] } ], "formatted_address": "中國上海市", "geometry": { "bounds": { "northeast": { "lat": 31.8727163, "lng": 122.2471487 }, "southwest": { "lat": 30.6755932, "lng": 120.8568046 } }, "location": { "lat": 31.2191829, "lng": 121.4456179 }, "location_type": "APPROXIMATE", "viewport": { "northeast": { "lat": 31.8727163, "lng": 122.2471487 }, "southwest": { "lat": 30.6755932, "lng": 120.8568046 } } }, "place_id": "ChIJBftfxTICsjUR_z-KXanY9fI", "types": [ "administrative_area_level_1", "political" ] }, { "address_components": [ { "long_name": "中國", "short_name": "CN", "types": [ "country", "political" ] } ], "formatted_address": "中國", "geometry": { "bounds": { "northeast": { "lat": 53.5609739, "lng": 134.7754563 }, "southwest": { "lat": 17.9996, "lng": 73.4994136 } }, "location": { "lat": 35.86166, "lng": 104.195397 }, "location_type": "APPROXIMATE", "viewport": { "northeast": { "lat": 53.5609739, "lng": 134.7754563 }, "southwest": { "lat": 17.9996, "lng": 73.4994136 } } }, "place_id": "ChIJwULG5WSOUDERbzafNHyqHZU", "types": [ "country", "political" ] } ], "status": "OK" }

根據經緯度根據谷歌地圖接口獲取到當前地址