Reputation: 15
when i provide the url given below , i am getting the proper rsults but
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 ;
when i am trying to use multiple types like :
school | university
it showing forced closed....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 ;
what mistake i am doing...
Upvotes: 0
Views: 2784
Reputation: 62419
Try to put parameters like where types like 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;
}
Upvotes: 0
Reputation: 178
This works for me when using multiple types:
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();
}
The emphasis here is on types="+URLEncoder.encode(types,"UTF-8")
Upvotes: 4
Reputation: 676
I friend now i got the multiple types support now. use uri builder class request 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();
}
Upvotes: 0
Reputation: 676
Hi friend i had same problem like you,after long time searching i found another solution for parsing google response using Volley api http://java.dzone.com/articles/android-%E2%80%93-volley-library Volley library for Android parse xml response?
volley liabrery has no request for xml but have string request and response, you can convert string into xml format than parse data as xml
Upvotes: 0