Google Maps Geolocation API: доступ не настроен

Я пытаюсь использовать API геолокации Google на Android. Я уверен, что у меня есть действительный apikey для Android, и я включил биллинг. Однако сервер возвращает

doman: useLimits reson: код доступа не настроен: 403

Может ли кто-нибудь решить эту проблему? PS: у меня нет корпоративной поддержки для разработки карт Google. Мой код указан ниже

JSONObject holder = new JSONObject();  
JSONArray cellarray = new JSONArray();  
JSONArray wifiarray = new JSONArray();
JSONObject cell = new JSONObject();
JSONObject wifi1 = new JSONObject();
JSONObject wifi2 = new JSONObject();
try {
    cell.put("cellId", cid);
    cell.put("locationAreaCode", lac); 
    cell.put("mobileCountryCode", mcc);  
    cell.put("mobileNetworkCode", mnc);
    cell.put("age", 0);
    cell.put("signalStrength", -95);
    cellarray.put(cell);

    wifi1.put("macAddress", "01:23:45:67:89:AB");
    wifi1.put("signalStrength", 8);
    wifi1.put("age", 0);
    wifi1.put("signalToNoiseRatio", -65);
    wifi1.put("channel", 8);
    wifiarray.put(wifi1);

    wifi2.put("macAddress", "01:23:45:67:89:AC");
    wifi2.put("signalStrength", 4);
    wifi2.put("age", 0);
    wifiarray.put(wifi2);

    holder.put("homeMobileCountryCode", mcc);
    holder.put("homeMobileNetworkCode", mnc);
    holder.put("radioType", "gsm");
    holder.put("carrier", "T-Mobile");
    holder.put("cellTowers", cellarray);
    holder.put("wifiAccessPoints", wifiarray);


} catch (JSONException e) {  
    e.printStackTrace();  
}
DefaultHttpClient client = new DefaultHttpClient();
HttpPost httpPost = new HttpPost("https://www.googleapis.com/geolocation/v1/geolocate?key="+API_key);
StringEntity stringEntity = null;  

try {  
    stringEntity = new StringEntity(holder.toString());  
    stringEntity.setContentType("application/json");

    Log.v("zf",stringEntity.getContentType().toString());

} catch (UnsupportedEncodingException e) {  
    e.printStackTrace();  
}

httpPost.setEntity(stringEntity);  
HttpResponse httpResponse = null;  
try {
    httpResponse = client.execute(httpPost);  
} catch (ClientProtocolException e) {  
    e.printStackTrace();  
} catch (IOException e) {  
    e.printStackTrace();  
} 

person zagfox    schedule 23.01.2013    source источник
comment
попробуйте добавить параметр датчика в конец вашего URL   -  person 1Mayur    schedule 02.03.2013
comment
В этом примере API геокодирования запрашивает ответ json на запрос по адресу 1600 Amphitheatre Parkway, Mountain View, CA: maps.googleapis.com/maps/api/geocode/ В этом примере мы оставили параметр датчика как переменная true_or_false, чтобы подчеркнуть, что вы должны явно установить это значение либо в true, либо в false.   -  person 1Mayur    schedule 02.03.2013


Ответы (2)


Возможная причина № 1: добавьте значение датчика к вашему URL-адресу, это НЕ обязательно!

Возможная причина № 2: включили ли вы службу геолокации в консоли API?

Возможная причина № 3. Настроили ли вы платежную информацию в консоли API?

person Goddchen    schedule 23.03.2013

Причина ошибки ясна, когда вы читаете строку ответа:

"code": 403,
"message": "There is a per-IP or per-Referer restriction configured on your API key and the request does not match these restrictions. Please use the Google Developers Console to update your API key configuration if request from this IP or referer should be allowed."

Перейдите в консоль разработчиков и в разделе «Учетные данные» добавьте свое приложение в разделе «Ограничить использование приложений для Android».

person Gabor    schedule 19.12.2015