0

当我提供下面给出的 url 时,我得到了正确的结果,但是

    String baseUrl = "https://maps.googleapis.com/maps/api/place/search/xml?location=";
    String last="&radius=20000&types=school&sensor=false&key=";

    URL = baseUrl + latitude + "," + longitude + last + API_KEY ;

当我尝试使用多种类型时:

学校| 大学

它显示强制关闭....EX

 String baseUrl = "https://maps.googleapis.com/maps/api/place/search/xml?location=";
    String last="&radius=20000&types=school|university&sensor=false&key=";

    URL = baseUrl + latitude + "," + longitude + last + API_KEY ;

我在做什么错...

4

4 回答 4

4

当使用多种类型时,这对我有用:

String keyString = "your_key";

String JSON_BASE = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=";
String types = "airport|hospital";
try {
        placesSearchStr=JSON_BASE+getLat()+","+getLng()+
                        "&radius=1000&sensor=false&types="+URLEncoder.encode(types,"UTF-8")+
                        "&key="+keyString;
    } catch (UnsupportedEncodingException e) {

        e.printStackTrace();
    }

这里的重点是types="+URLEncoder.encode(types,"UTF-8")

于 2013-10-28T22:06:34.617 回答
0

我的朋友现在我得到了多种类型的支持。使用 uri builder 类请求 url

public String getURL(double lat, double lng){
    Uri uri = new Uri.Builder()
    .scheme("https")
    .authority("maps.googleapis.com")
    .path("maps/api/place/search/xml")
    .appendQueryParameter("location", lat+",",lng)
    .appendQueryParameter("radius", "5000")
    .appendQueryParameter("types",   "zoo|travel_agency|taxi_stand|pet_store|museum|movie_theater|library|jewelry_store|hospital|clothing_store|atm|church|bus_station|art_gallery|bank|beauty_salon|city_hall|book_store|park|shopping_mall|train_station|airport")
    .appendQueryParameter("sensor", "true")
    .appendQueryParameter("key", "your key")
    .build();
    return uri.toString();
}
于 2013-08-15T18:44:30.543 回答
0

尝试将参数放在 where 类型中,例如String types = "cafe|restaurant";

try {
    HttpRequestFactory httpRequestFactory = createRequestFactory(HTTP_TRANSPORT);
    HttpRequest request = httpRequestFactory
            .buildGetRequest(new GenericUrl(PLACES_SEARCH_URL));
    request.getUrl().put("key", API_KEY);
    request.getUrl().put("location", _latitude + "," + _longitude);
    request.getUrl().put("radius", _radius); // in meters
    request.getUrl().put("sensor", "false");

    if(types != null)
        request.getUrl().put("types", types);

    PlacesList list = request.execute().parseAs(PlacesList.class);
    // Check log cat for places response status
    Log.d("Places Status", "" + list.status);
    return list;

} catch (HttpResponseException e) {
    Log.e("Error:", e.getMessage());
    return null;
}
于 2014-11-29T12:31:09.653 回答
0

嗨朋友我和你有同样的问题,经过长时间的搜索,我找到了另一个使用 Volley api http://java.dzone.com/articles/android-%E2%80%93-volley-library解析谷歌响应的解决方案 Volley 库Android 解析 xml 响应?

volley liabrery 没有对 xml 的请求,但有字符串请求和响应,您可以将字符串转换为 xml 格式而不是将数据解析为 xml

于 2013-08-08T06:34:10.650 回答