kar*_*ran 0 android autocompletetextview google-geocoding-api google-places-api google-maps-android-api-2
我正在使用此处提出的问题的代码自动完成textview google places api description - > place_id.我更改了代码以将其添加到我的应用程序中.当我运行代码时,它在我运行代码时给出了以下响应
07-28 11:17:19.244: E/result(350): {"error_message":"This API project is not authorized to use this API. Please ensure that this API is activated in the APIs Console: Learn more: https:\/\/code.google.com\/apis\/console","predictions":[],"status":"REQUEST_DENIED"}
Run Code Online (Sandbox Code Playgroud)
我搜索了一些线程,并从下面的线程
我按照建议做了以下步骤.
Places API
从控制台启用.Geocoding API
从控制台启用.当我运行代码时,它仍然显示上面提到的错误.我是否需要从控制台启用任何其他API.
除此之外,地图工作得很好.如果您想知道这是我在清单中添加的api密钥.
<!-- Goolge Maps API Key Development mode -->
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyAbo3luzbyQTuuPLOyo_Ml***********" />
Run Code Online (Sandbox Code Playgroud)
我正在直接添加服务器密钥以请求URL,如下所示
private ArrayList<String> autocomplete(String input) {
ArrayList<String> resultList = null;
HttpURLConnection conn = null;
StringBuilder jsonResults = new StringBuilder();
try {
StringBuilder sb = new StringBuilder(PLACES_API_BASE + TYPE_AUTOCOMPLETE + OUT_JSON);
sb.append("?key=" + API_KEY);
sb.append("&input=" + URLEncoder.encode(input, "utf8"));
URL url = new URL(sb.toString());
conn = (HttpURLConnection) url.openConnection();
InputStreamReader in = new InputStreamReader(conn.getInputStream());
// Load the results into a StringBuilder
int read;
char[] buff = new char[1024];
while ((read = in.read(buff)) != -1) {
jsonResults.append(buff, 0, read);
}
} catch (MalformedURLException e) {
Log.e(LOG_TAG, "Error processing Places API URL", e);
return resultList;
} catch (IOException e) {
Log.e(LOG_TAG, "Error connecting to Places API", e);
return resultList;
} finally {
if (conn != null) {
conn.disconnect();
}
}
try {
// Create a JSON object hierarchy from the results
JSONObject jsonObj = new JSONObject(jsonResults.toString());
JSONArray predsJsonArray = jsonObj.getJSONArray("predictions");
Log.e("result",jsonObj.toString());
// Extract the Place descriptions from the results
resultList = new ArrayList<String>(predsJsonArray.length());
for (int i = 0; i < predsJsonArray.length(); i++) {
resultList.add(predsJsonArray.getJSONObject(i).getString("description")+ "," + predsJsonArray.getJSONObject(i).getString("place_id") );
}
} catch (JSONException e) {
Log.e(LOG_TAG, "Cannot process JSON results", e);
}
return resultList;
}
Run Code Online (Sandbox Code Playgroud)
请帮忙.
归档时间: |
|
查看次数: |
1277 次 |
最近记录: |