“权限被拒绝:在访问地理编码URL时尝试未经许可访问被阻止的收件人。(mapped-IPv4)”

时间:2016-04-26 11:13:43

标签: google-maps google-app-engine google-maps-api-3 google-api google-geocoding-api

我使用google geocode api。 我的代码是:

HttpGet httpGet = new HttpGet( "https://maps.googleapis.com/maps/api/geocode/json?latlng="+latitude+","+longitude+"&key="+server key"); 

DefaultHttpClient httpClient = new DefaultHttpClient();

HttpResponse httpResponse = httpClient.execute(httpGet);

但是我得到了以下错误:

  

异常消息:权限被拒绝:未经许可尝试访问被阻止的收件人。 (映射-IPv4)的

相同的代码在本地运作良好,Appengine帐户是付费帐户。

请给我解决方案..

2 个答案:

答案 0 :(得分:0)

根据this most Google IPs are blocked on GAE

  

私有,广播,多播和Google IP范围(下面列入白名单的除外)将被屏蔽

答案 1 :(得分:0)

我得到答案:

    try
    {
        URL url = new URL("https://maps.googleapis.com/maps/api/geocode/json?latlng="+latitude+","+longitude+"&key="+EnvirnomentConstant.GEO_LOCATION_KEY);
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setRequestMethod("GET");
        conn.setRequestProperty("Accept", "application/json");

        if (conn.getResponseCode() != 200) {
            throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode());
        }

        String result = IOUtils.toString((conn.getInputStream()), StandardCharsets.UTF_8);



        ObjectMapper objectMapper = new ObjectMapper();
        Map<String, Object> map = new HashMap<String, Object>();

        map = objectMapper.readValue(result, Map.class);
        List<Map<String, Object>> countries = new ArrayList<Map<String,Object>>();
        List<Map<String, Object>> countries1 = new ArrayList<Map<String,Object>>();
        countries = (List<Map<String, Object>>) map.get("results");
        for (Map<String, Object> countryMap : countries){
            if(countryMap.get("types").toString().contains("country")){
                countries1 = (List<Map<String, Object>>) countryMap.get("address_components");
                for (Map<String, Object> countryMap1 : countries1){
                    countryName =  countryMap1.get("long_name").toString();
                    break;
                }   
            }
        }
        m_ObjLog.warning("countryName: "+countryName);
        return countryName;
    }catch(Exception e)
    {
        ErrorHandler.errorHandler(this.getClass().getSimpleName(), e);
        return null;
    }