Google place api不支持多种类型

时间:2012-04-20 18:58:47

标签: android google-places-api google-places

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

    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 个答案:

答案 0 :(得分: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")

答案 1 :(得分:0)

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

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

答案 2 :(得分:0)

我的朋友现在我得到了多种类型的支持。使用uri构建器类请求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();
}

答案 3 :(得分:0)

尝试输入像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;
}