2012-04-20 71 views
0

當我提供下面給出的網址,我得到正確的rsults但谷歌的地方API不支持多種類型的

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 ; 

我在做什麼錯誤...

+0

請發佈日誌,以便我們可以看到您收到的異常一個堆棧跟蹤。 – 2012-04-20 19:09:25

+0

無法啓動活動ComponentInfo {com.run.trial/com.run.trial.RuntrialActivity}:java.lang.NullPointerException – santosh407 2012-04-22 17:01:01

+0

at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1768) – santosh407 2012-04-22 17:01:32

回答

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(); 
} 
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")

+0

謝謝你,像魅力一樣工作。 – Satheesh 2017-06-02 07:28:01

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; 
} 
相關問題