Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/203.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
Android中与地理编码器的错误距离_Android_Google Maps_Location_Google Geocoder - Fatal编程技术网

Android中与地理编码器的错误距离

Android中与地理编码器的错误距离,android,google-maps,location,google-geocoder,Android,Google Maps,Location,Google Geocoder,我有2个文本框,其中我提供了源地址和目标地址 1)资料来源=古吉拉特邦艾哈迈达巴德沙伊巴桥下的沙伊巴格 2)目的地=古吉拉特邦艾哈迈达巴德纳夫兰普拉什里亚斯殖民地CG路 距离=4.6(来自谷歌地图)和&2.6656852(使用距离定位法) 我不知道为什么我走错了距离。我在我的代码中有一个疑问,那就是我使用了getFromLocationName方法,并且我传递了一个参数来只得到一个结果。这有什么区别吗?任何人有任何想法,请帮忙。谷歌地图给你道路距离,地理编码器给你乌鸦飞的距离。使用谷歌地图API

我有2个文本框,其中我提供了源地址和目标地址

1)资料来源=古吉拉特邦艾哈迈达巴德沙伊巴桥下的沙伊巴格

2)目的地=古吉拉特邦艾哈迈达巴德纳夫兰普拉什里亚斯殖民地CG路

距离=4.6(来自谷歌地图)和&2.6656852(使用距离定位法)


我不知道为什么我走错了距离。我在我的代码中有一个疑问,那就是我使用了getFromLocationName方法,并且我传递了一个参数来只得到一个结果。这有什么区别吗?任何人有任何想法,请帮忙。

谷歌地图给你道路距离,地理编码器给你乌鸦飞的距离。

使用谷歌地图API解决了这个问题。希望它能帮助其他人。它能给你精确的距离

final ProgressDialog dialog = ProgressDialog.show(AutoActivity.this, "", "Calculating...");

            new Thread(new Runnable() {
                @Override
                public void run() {
                    try {
                        float distance = 0.0f;
                        StringBuffer url = new StringBuffer("http://maps.googleapis.com/maps/api/directions/json?origin=");
                        url.append(source_input.getText().toString().replace(" ", "").trim().toString());
                        url.append("&destination=");
                        url.append(destination_input.getText().toString().replace(" ", "").trim().toString());
                        url.append("&sensor=false");

                        DefaultHttpClient httpClient = new DefaultHttpClient();
                        HttpGet httpGet = new HttpGet(url.toString());
                        HttpResponse httpResponse = httpClient.execute(httpGet);
                        HttpEntity httpEntity = httpResponse.getEntity();
                        String line = EntityUtils.toString(httpEntity);

                        JSONObject jsonObject = new JSONObject(line);
                        JSONArray jsonarray = jsonObject.getJSONArray("routes").getJSONObject(0).getJSONArray("legs");

                        for (int i = 0; i < jsonarray.length(); i++) {
                            JSONObject obj = jsonarray.getJSONObject(i);
                            distance  = Float.valueOf(obj.getJSONObject("distance").getString("text").replace("km", ""));
                            System.out.println("Distance == " + obj.getJSONObject("distance").getString("text").replace("km", ""));
                        }


                        kmVal = BigDecimal.valueOf(distance);
                        calculateFares();
                    } catch (IOException e) {
                        e.printStackTrace();
                    } catch (Exception e) {
                        e.printStackTrace();
                    } finally {
                        if (dialog!=null) {
                            dialog.dismiss();   
                        }
                    }
                }
            }).start();
final ProgressDialog dialog=ProgressDialog.show(AutoActivity.this,“,”计算…);
新线程(newrunnable()){
@凌驾
公开募捐{
试一试{
浮动距离=0.0f;
StringBuffer url=新的StringBuffer(“http://maps.googleapis.com/maps/api/directions/json?origin=");
append(source_input.getText().toString().replace(“,”).trim().toString());
url.append(“&destination=”);
append(destination_input.getText().toString().replace(“,”).trim().toString());
追加(“&sensor=false”);
DefaultHttpClient httpClient=新的DefaultHttpClient();
HttpGet-HttpGet=newhttpget(url.toString());
HttpResponse HttpResponse=httpClient.execute(httpGet);
HttpEntity HttpEntity=httpResponse.getEntity();
String line=EntityUtils.toString(httpEntity);
JSONObject JSONObject=新的JSONObject(行);
JSONArray JSONArray=jsonObject.getJSONArray(“路由”).getJSONObject(0).getJSONArray(“腿”);
for(int i=0;i
尝试计算从源lat、lng和目的lat的距离,lngI需要这两个位置的道路距离。有没有可能通过android中的地理编码器和定位API,或者必须使用谷歌地图。检查这个,嗯……对……那么有什么解决方案。解决方案是什么?这些是不同的事情。你想得到什么?那要复杂得多。你需要一个服务来提供这些信息,所以基本上我必须使用谷歌地图服务。如果我错了,请纠正我。我看过API,这就是距离。我想你可以使用距离矩阵API
final ProgressDialog dialog = ProgressDialog.show(AutoActivity.this, "", "Calculating...");

            new Thread(new Runnable() {
                @Override
                public void run() {
                    try {
                        float distance = 0.0f;
                        StringBuffer url = new StringBuffer("http://maps.googleapis.com/maps/api/directions/json?origin=");
                        url.append(source_input.getText().toString().replace(" ", "").trim().toString());
                        url.append("&destination=");
                        url.append(destination_input.getText().toString().replace(" ", "").trim().toString());
                        url.append("&sensor=false");

                        DefaultHttpClient httpClient = new DefaultHttpClient();
                        HttpGet httpGet = new HttpGet(url.toString());
                        HttpResponse httpResponse = httpClient.execute(httpGet);
                        HttpEntity httpEntity = httpResponse.getEntity();
                        String line = EntityUtils.toString(httpEntity);

                        JSONObject jsonObject = new JSONObject(line);
                        JSONArray jsonarray = jsonObject.getJSONArray("routes").getJSONObject(0).getJSONArray("legs");

                        for (int i = 0; i < jsonarray.length(); i++) {
                            JSONObject obj = jsonarray.getJSONObject(i);
                            distance  = Float.valueOf(obj.getJSONObject("distance").getString("text").replace("km", ""));
                            System.out.println("Distance == " + obj.getJSONObject("distance").getString("text").replace("km", ""));
                        }


                        kmVal = BigDecimal.valueOf(distance);
                        calculateFares();
                    } catch (IOException e) {
                        e.printStackTrace();
                    } catch (Exception e) {
                        e.printStackTrace();
                    } finally {
                        if (dialog!=null) {
                            dialog.dismiss();   
                        }
                    }
                }
            }).start();