2012-03-09 130 views
1

我得到我的位置由一個地址,我用這個website得到谷歌從JSON座標映射

我得到的JSON數據,但我不知道如何在我的Android應用閱讀。

{ 
    "name": "plaza mayor 1 madrid España", 

    "Status": { 

    "code": 200, 

    "request": "geocode" 

    }, 

    "Placemark": [ { 

    "id": "p1", 

    "address": "Plaza Mayor, 1, 28012 Madrid, España", 

    "AddressDetails": { 

    "Accuracy" : 8, 

    "Country" : { 

     "AdministrativeArea" : { 

     "AdministrativeAreaName" : "Comunidad de Madrid", 

     "SubAdministrativeArea" : { 

      "Locality" : { 

       "LocalityName" : "Madrid", 

       "PostalCode" : { 

        "PostalCodeNumber" : "28012" 

       }, 

       "Thoroughfare" : { 

        "ThoroughfareName" : "Plaza Mayor, 1" 

       } 

      }, 

      "SubAdministrativeAreaName" : "Madrid" 

     } 

     }, 

     "CountryName" : "España", 

     "CountryNameCode" : "ES" 

    } 

}, 

    "ExtendedData": { 

     "LatLonBox": { 

     "north": 40.4164186, 

     "south": 40.4137207, 

     "east": -3.7053139, 

     "west": -3.7080118 

     } 

    }, 

    "Point": { 

     "coordinates": [ -3.7066379, 40.4150359, 0 ] 

    } 

    } ] 

} 

如何讀取「座標」標籤?

預先感謝您!

回答

3

分析它,首先,然後訪問的各種元素:

JSONObject response = new JSONObject(responseAsString); 
JSONObject point = response.getJSONArray("Placemark").getJSONObject(0).getJSONObject("Point"); 

double lat = point.getJSONArray("coordinates").getDouble(0); 

+0

它工作完美!非常感謝你! – user1256477 2012-03-09 16:27:48

0

我會建議使用某種框架來處理你的Json數據,這裏是一個很好的例子。然後,您可以將數據作爲常規對象處理。

Sending and Parsing JSON Objects

祝你好運!

+0

非常感謝您的鏈接,真正有用的! – user1256477 2012-03-09 16:28:26