2013-01-23 103 views
6

我想在Android上使用谷歌地理定位api。我相信我有Android的有效API,我已啓用結算。 但是,服務器返回谷歌地圖地理位置API:訪問未配置

杜曼:usageLimits 振振有辭:訪問未配置 代碼:403

誰能解決這個問題? PS:我沒有企業支持谷歌地圖開發。我的代碼如下:

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

嘗試添加傳感器參數去結束你的網址 – 1Mayur

+1

在這個例子中,地理編碼API會針對「1600劇場百匯,山景,CA」的查詢的JSON響應: http://maps.googleapis.com/maps/api/geocode/json?address = 1600 + Amphitheater + Parkway,+ Mountain + View,+ CA&sensor = true_or_false 我們在此示例中將傳感器參數作爲變量true_or_false加以強調,以表明您必須將此值設置爲明確地爲真或假。 – 1Mayur

回答

0

可能的原因#1:將傳感器值添加到您的網址,它不是可選的!

可能的原因#2:您是否在API控制檯中啓用了Geolocation服務?

可能的原因#3:您是否在API控制檯中設置了結算信息?

"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應用」添加應用程序:

0

錯誤的原因,當你閱讀的字符串迴應是清楚的。