Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/328.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Android:Google API v.3给出了无效的_请求,但在浏览器中执行良好_Java_Android_Google Maps_Google Maps Api 3 - Fatal编程技术网

Java Android:Google API v.3给出了无效的_请求,但在浏览器中执行良好

Java Android:Google API v.3给出了无效的_请求,但在浏览器中执行良好,java,android,google-maps,google-maps-api-3,Java,Android,Google Maps,Google Maps Api 3,我需要对地址进行地理编码,并从城市获取纬度、经度、邮政编码和其他信息 当我在Android上使用此请求时 我收到无效的_请求作为响应。但当我在浏览器中或在REST客户端的帮助下尝试此链接时,一切正常 这一要求也同样适用: -Horní+Blatná&区域=CZE&传感器=错误 原因可能是什么 Url创建: StringBuilder addressUrl = new StringBuilder(); if (order.getDepartur

我需要对地址进行地理编码,并从城市获取纬度、经度、邮政编码和其他信息

当我在Android上使用此请求时

我收到无效的_请求作为响应。但当我在浏览器中或在REST客户端的帮助下尝试此链接时,一切正常

这一要求也同样适用:

-Horní+Blatná&区域=CZE&传感器=错误

原因可能是什么

Url创建:

     StringBuilder addressUrl  = new StringBuilder();
                    if (order.getDepartureAddress().getStreet()!=null && !order.getDepartureAddress().getStreet().equalsIgnoreCase(""))
                        addressUrl.append(order.getDepartureAddress().getStreet() + ", ");
                    if (order.getDepartureAddress().getHouseNumber()!=null && ! order.getDepartureAddress().getHouseNumber().equalsIgnoreCase(""))
                        addressUrl.append(order.getDepartureAddress().getHouseNumber() + ", ");
                    if (order.getDepartureAddress().getCity()!=null && !order.getDepartureAddress().getCity().equalsIgnoreCase(""))
                        addressUrl.append(order.getDepartureAddress().getCity() );
                    if (order.getDepartureAddress().getCountryCode()!=null && !order.getDepartureAddress().getCountryCode().equalsIgnoreCase(""))
                        addressUrl.append("&region="+order.getDepartureAddress().getCountryCode() );
                    addressUrl.append("&sensor=false");
/* 
Constants.URL_GEOCODING = https://maps.googleapis.com/maps/api/geocode/json?address=    
*/
String finalUrl = Constants.URL_GEOCODING + addressUrl.toString();

/* request execution : */


    public static JSONObject readJsonFromUrl(String urlStr) throws IOException, JSONException {
            URL url = new URL(urlStr);
            URI uri = null;
            URI uri2= null;
            try {
                uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(), url.getQuery(), url.getRef());
                url = uri.toURL();
                uri2 = new URI(url.toString().replace("%20", "+"));
            } catch (URISyntaxException e) {
                e.printStackTrace();
            }
            url = uri2.toURL();
            Log.i(TAG + " requested url", url.toString());
            InputStream is = url.openStream();
            try {
                BufferedReader rd = new BufferedReader(new InputStreamReader(is, Charset.forName("UTF-8")));
                String jsonText = readAll(rd);
                JSONObject json = new JSONObject(jsonText);
                return json;
            } finally {
                is.close();
            }
        }

这里有一个想法:检查logcat的输出

如果请求时间和从谷歌发回数据的时间过于接近,谷歌可能会认为你是垃圾邮件发送者,并在第二次请求时拒绝访问服务器


这种情况下的解决方案是,如果有下一个\u页面\u令牌,请等待1秒,然后发送后续请求。

我喜欢你的名字。也许你有编码问题。请添加你称之为URL的android代码将其添加到我的问题中