且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Android中使用Google Places API?

更新时间:2023-01-18 13:20:32

您可以通过Json对其进行解析.

You can parse it by Json.

如果看到您的网址包含xml

if you see your url contains xml here . This will give response in xml.

使用xml输出:

<PlaceSearchResponse>
<status>REQUEST_DENIED</status>
</PlaceSearchResponse>

只需将其替换为json,例如

Just replace it with json like this . This will give response in Json.

使用Json的输出:

{
   "html_attributions" : [],
   "results" : [],
   "status" : "REQUEST_DENIED"
}

请参见用于解析

try
{
    HttpPost httppost = new HttpPost("https://maps.googleapis.com/maps/api/place/search/json?&location=17.739290150000002,83.3071201&radius=6000&names=hospital&sensor=true&key=yourkeyhere");
    HttpClient httpclient = new DefaultHttpClient();
    response = httpclient.execute(httppost);
    String data = EntityUtils.toString(response.getEntity());
    System.out.println(data);
    //parse with Json, Gson, Jackson

} catch (Exception e) {
    e.printStackTrace();
}