【问题标题】:Google Maps Geolocation api : access not configuredGoogle Maps Geolocation api:未配置访问权限
【发布时间】:2013-01-06 14:17:13
【问题描述】:

我正在尝试在 Android 上使用 google geolocation api。我确定我有适用于 android 的有效 apikey 并且我已启用计费。 但是,服务器返回

域: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();  
} 

【问题讨论】:

  • 尝试将传感器参数添加到您的网址末尾
  • 在本例中,Geocoding API 请求一个 json 响应,用于查询“1600 Amphitheatre Parkway, Mountain View, CA”:maps.googleapis.com/maps/api/geocode/… 我们在本例中将传感器参数保留为变量true_or_false 强调您必须明确将此值设置为 true 或 false。

标签: android geolocation google-maps-android-api-2


【解决方案1】:

可能的原因 #1:将传感器值添加到您的 url,它不是可选的!

可能的原因 #2:您是否在 API 控制台中启用了 Geolocation 服务?

可能的原因 #3:您是否在 API 控制台中设置了账单信息?

【讨论】:

    【解决方案2】:

    当您阅读字符串响应时,错误的原因就很清楚了:

    "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 应用程序的使用”下添加您的应用程序。

    【讨论】:

      猜你喜欢
      • 2014-09-23
      • 2014-01-16
      • 2017-02-11
      • 2016-10-22
      • 2013-07-15
      • 2020-08-11
      • 2017-12-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多