2013-01-23 17 views
6

Sto cercando di utilizzare google geolocation api su Android. Sono sicuro di avere apikey valido per Android e ho abilitato la fatturazione. Tuttavia, il server restituisceGoogle Maps Geolocation api: accesso non configurato

Doman: usageLimits reson: l'accesso non è configurato codice: 403

Qualcuno potrebbe risolvere questo problema? PS: non ho un supporto aziendale per lo sviluppo della mappa di google. Il mio codice è elencato sotto

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(); 
} 
+0

prova ad aggiungere param sensore al fine dell'URL – 1Mayur

+1

In questo esempio, l'API Geocoding richiede una risposta JSON per una query su "1600 Amphitheatre Parkway, Mountain View, CA": http://maps.googleapis.com/maps/api/geocode/json? address = 1600 + Amphitheatre + Parkway, + Mountain + View, + CA & sensor = true_or_false Abbiamo lasciato il parametro del sensore in questo esempio come una variabile true_or_false per sottolineare che è necessario impostare questo valore su sia vero che falso esplicitamente. – 1Mayur

risposta

0

Possibile motivo # 1: aggiungi il valore del sensore al tuo URL, NON è opzionale!

Motivo possibile # 2: hai abilitato il servizio di geolocalizzazione nella tua console API?

Motivo possibile # 3: hai impostato le informazioni di fatturazione nella tua console API?

0

La causa dell'errore è chiaro quando si legge la risposta stringa:

"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." 

Vai alla console sviluppatori e in Credenziali aggiungere la vostra applicazione sotto "Limitare l'uso di tue app Android".

Problemi correlati