2013-01-23 66 views
6

Tôi đang cố sử dụng api vị trí địa lý của google trên Android. Tôi chắc chắn rằng tôi có apikey hợp lệ cho android và tôi đã kích hoạt thanh toán. Tuy nhiên, máy chủ trảVị trí địa lý của Google Maps api: quyền truy cập không được định cấu hình

doman: usageLimits reson: truy cập không được cấu hình mã: 403

thể bất cứ ai giải quyết vấn đề này? PS: Tôi không có hỗ trợ doanh nghiệp để phát triển bản đồ google. Mã của tôi được liệt kê bên dưới

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

thử thêm thông số cảm biến vào cuối url của bạn – 1Mayur

+1

Trong ví dụ này, API mã hóa địa lý yêu cầu phản hồi json cho truy vấn trên "1600 Amphitheater Parkway, Mountain View, CA": http://maps.googleapis.com/maps/api/geocode/json? address = 1600 + Amphitheatre + Parkway, + Mountain + View, + CA & sensor = true_or_false Chúng tôi đã để lại tham số cảm biến trong ví dụ này dưới dạng biến true_or_false để nhấn mạnh rằng bạn phải đặt giá trị này thành đúng hoặc sai một cách rõ ràng. – 1Mayur

Trả lời

0

Lý do có thể # 1: Thêm giá trị cảm biến vào url của bạn, KHÔNG PHẢI là tùy chọn!

Lý do có thể # 2: Bạn đã bật dịch vụ Vị trí địa lý trong bảng điều khiển API chưa?

Lý do có thể # 3: Bạn đã thiết lập thông tin thanh toán trong bảng điều khiển API chưa?

0

Nguyên nhân của lỗi này là rõ ràng khi bạn đọc những phản ứng chuỗi:

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

Chuyển đến Developers Console và dưới Credentials thêm ứng dụng của bạn trong phần "Hạn chế sử dụng các ứng dụng Android của bạn".

Các vấn đề liên quan