在寻找Android的当前位置 [英] Finding Current Location in android

查看:168
本文介绍了在寻找Android的当前位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找到当前的位置,这是我的code。

 的LocationManager mlocManager =(的LocationManager)getSystemService(Context.LOCATION_SERVICE);
        位置位置=新的位置(mlocManager.GPS_PROVIDER); 的System.out.println(***经度**+ location.getLongitude());
        的System.out.println(***纬度**+ location.getLatitude());

但是当我运行的应用程序,它总是显示0.0
任何人都可以看到这个问题?


解决方案

 位置位置=新的位置(mlocManager.GPS_PROVIDER);

写这个语句后,如果你把光标放在位置你会知道这句话的意思extact

根据谷歌文档


  

以上构造一个新的位置。默认情况下,时间,纬度,
  经度和numSatellites是0; hasAltitude,hasSpeed​​和
  hasBearing是假的;并没有额外的信息。


您需要解雇 requestLocationUpdate 来获取纬度和放大器; LON(如有)。

此外,由于正在运行的Emulator.You这个例子中需要模拟发送纬度和放大器;经度
手动。

I am trying to find current location, and this is my code.

 LocationManager mlocManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);        
        Location location =new Location(mlocManager.GPS_PROVIDER);      

 System.out.println("***longitude **"+location.getLongitude());
        System.out.println("***latitude **"+location.getLatitude());

but when i run app it always display 0.0 can anyone see the problem?

解决方案

Location location =new Location(mlocManager.GPS_PROVIDER); 

after writing this statement if you put your cursor over Location You will come to know extact meaning of this statement.

As per Google Doc

above Constructs a new Location. By default, time, latitude, longitude, and numSatellites are 0; hasAltitude, hasSpeed, and hasBearing are false; and there is no extra information.

You need to fire requestLocationUpdate to get Lat & lon(If any).

Also since you are running this example on Emulator.You will need to emulate send Lat & Lon manually.

这篇关于在寻找Android的当前位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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