Android 앱의 좌표에서 위치 주소를 가져 오려고합니다. 앞서 언급 한 바와 같이 here, 나는 API 키를 얻었고 브라우저의 표준 URL을 테스트하여 성공적인 응답을 반환했습니다. 내 안드로이드 응용 프로그램에서 동일한 URL을 시도하지만,이 -Google 역 지오 코딩 URL 요청이 Android 앱에서 비어있는 (ZERO_RESULTS가 아닌) 응답을 반환합니다.
{
(단지 여는 중괄호는) 내가 가진 응답입니다. URL에
private static class GetLocationAddress extends AsyncTask<String, Void, String> {
private WeakReference<CreateUser> reference;
GetLocationAddress(CreateUser context) {
reference = new WeakReference<>(context);
}
@Override
protected String doInBackground(String... strings) {
try {
HttpURLConnection connection = (HttpURLConnection) new URL(strings[0]).openConnection();
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String result = reader.readLine();
connection.disconnect();
Log.i("JSON Response is ", result);
return result;
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
}
모든 매개 변수가 브라우저에서 작업하는
if (bestLocation != null) {
locationLatitude = bestLocation.getLatitude();
locationLongitude = bestLocation.getLongitude();
String latlng = locationLatitude + "," + locationLongitude;
final String location_type = "RANGE_INTERPOLATED";
final String API_KEY = "MY_WORKING_KEY";
final String url = "https://maps.googleapis.com/maps/api/geocode/json?latlng="
+ latlng + "&location_type=" + location_type + "&key=" + API_KEY;
new GetLocationAddress(CreateUser.this).execute(url);
}
GetLocationAddress :
여기 내 자바 코드입니다. 나는 API
을 모두 제한되지 않고 Android 앱에만 사용하도록 시도했으며, 디버그 및 릴리스 키 저장소 모두에 대해 SHA-1
지문을 설정했지만 그 결과는 동일합니다. 도와주세요.
업데이트 :이 API 콘솔을 확인하고 (오류 403), API가 안드로이드로 제한되는 동안에도 내 응용 프로그램의 지문과 애플 리케이션을 금지 나의 모든 요청이 처리 된 것으로 나타났습니다
제공됩니다. 디버그 및 릴리스 지문의 패키지 이름은 동일합니다. 또한 내 앱이 응답을받은 후에도 API 요청 수가 콘솔에서 조금만 업데이트된다는 사실이 관찰되었습니다.
이 로그 캣을 게시이
AsyncTask
클래스를 호출합니다. – Dharmishtha결과 문자열을 JSON 구문 분석하려고하지 않으면 오류 또는 예외가 발생하지 않습니다. – Nithin
API 요청을 할 수 있습니까? – Dharmishtha