【发布时间】:2016-09-14 21:59:13
【问题描述】:
所以我正在构建一个 android 应用程序,该应用程序可以使用 google places api 获取附近的餐馆,但是当我使用多个关键字时,我的 url 格式有点问题, 当我在浏览器中测试 url 时它运行良好,但是当我在 android studio 中获取 url 时出现问题,带有括号的部分被排除在 url 之外,所以我需要的只是如何在 android 中将括号放在 url 中。
这是url格式化的主要代码:
String keywordText;
String keyword="(Pizza)and(sushi)";
String BASE_URL="https://maps.googleapis.com/maps/api/place/nearbysearch/json?";
String API_KEY= "AIzaSyBg-iwzAjavEUVV9hOQUr0JljZHL7XFRkQ";
String ApiKey;
String locationText;
public void onLocationComplete(Location location) {
Log.e("onLocationComlete", keyword);
keywordText = "&keyword=" + keyword;
ApiKey = "&key=" + API_KEY;
radiusText = "&radius=" + radius;
locationText = "&location=" + location.getLatitude() + "," + location.getLongitude();
url = BASE_URL + locationText + radiusText + keywordText + ApiKey;
loc = location;
new FetchFromServerTask(Restaurants.this, 0).execute(url);
}
但是我从控制台得到了这个不起作用的 url:image
有没有办法在网址中包含括号或使用多个关键字搜索地点??
【问题讨论】:
-
看看URLEncoder类。
-
如果不能发送意味着,使用post方法发送位置数据而不是get。
-
你可能想看看使用URI Builder
标签: android url encoding formatting google-places-api