没有得到真正的纬度和经度?只获得0.0 0.0 [英] Not getting the real latitude and longitude? Only getting 0.0 0.0

查看:222
本文介绍了没有得到真正的纬度和经度?只获得0.0 0.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面,以获得纬度和位置的经度,但我用这code所有我得到是北纬0.0,东经0.0 code发现的纬度和logitude,我使用下面给出了,我也正在测试中Genymotion模拟器这个code和所有的打印日志中是0.0 0.0,因为如果(address.size()> 0)是没有得到satisfyied谁能告诉我在哪里脚麻还是因为模拟器。

Here I am using this code in order to get the latitude and longitude of the location but all that I am getting is latitude 0.0 and longitude 0.0 the code to find the latitude and logitude that I am using is given as below , Also I am testing this code in Genymotion emulator and all that is printed in the log is 0.0 0.0 because the if(address.size()>0) is not getting satisfyied can anyone tell where am I going wrong or is it because of emulator.

Geocoder geo = new Geocoder(getActivity());
            try {
                List<Address> address = geo.getFromLocationName(str_ELocation,1);
                if (address.size() > 0) {
                    Log.d("List Size : ", "" + address.size());
                    latitude = address.get(0).getLatitude();
                    longitude = address.get(0).getLongitude();
                } else {
                    Log.d("In Else", "In Else");
                }
            } catch (IOException e) {
                // TODO: handle exception
                e.printStackTrace();
            }

            Log.d("LONGITUDE AND LATITUDE", "" + longitude + "" + latitude);

另外还有没有其他更简单的解决方案,只要找到经度和纬度。我在使用碎片这一点,所以我使用getActivity()在这里,而不是myClassName.this。

Also is there any other simpler solution to just find latitude and longitude. I am using this in Fragment and so I am using getActivity() here instead of myClassName.this.

推荐答案

我猜你没有使用的是获得此信息的后端服务。

I'm guessing you don't have a backend service you are using to obtain this information.

注意 文档说

的地理位置codeR类需要不包含在后端服务
  Android核心框架。地缘codeR查询方法将返回
  空列表如果在平台没有后端服务。使用
  是present()方法来确定是否一个地理codeR实施
  存在。

The Geocoder class requires a backend service that is not included in the core android framework. The Geocoder query methods will return an empty list if there no backend service in the platform. Use the isPresent() method to determine whether a Geocoder implementation exists.

这也应该在后台完成如果不是已经在这样做。

This should also be done on a background Thread if not already being done.

您可能会更好使用的LocationManager

请务必开始拥有它是如何工作的,应当执行(这部分较短)的了解之前,阅读它的文档。

Be sure to read those docs on it before beginning to have an understanding of how it works and should be implemented (That portion is short).

<一个href=\"http://stackoverflow.com/questions/2227292/how-to-get-latitude-and-longitude-of-the-mobiledevice-in-android\">Here是一个可以让你开始一个例子

这样的事应该在后台完成并没有对 UI线程。并有能返回你所需要的值听众。

Anything like this should be done on a background Thread and not on the UI Thread. And there are listeners which can return the values you need.

全面披露:我没有使用GPS,但我通过阅读文档;)

这篇关于没有得到真正的纬度和经度?只获得0.0 0.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆