用户未找到位置 - 经度和纬度的android [英] User location not found :- latitude and longitude in android

查看:168
本文介绍了用户未找到位置 - 经度和纬度的android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的code putput总是在那张其他部分。 IT手段{}位置为null。

有什么建议?

  locManager =(的LocationManager)getSystemService(Context.LOCATION_SERVICE);
locManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,0,0,LocationListener的);
位置= locManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);            如果(位置!= NULL)
            {
        双纬度= location.getLatitude();
        双经度= location.getLongitude();            }其他{
                //
            }
.....
.....
....


解决方案

如果locManager.getLastKnownLocation(LocationManager.GPS_PROVIDER)返回null,这意味着你从来没有被定位。

如果你想获得新的位置,你应该让你的活动扩展LocationListener的接口,并实现以下。

 公共无效onLocationChanged(地点){
    // code到位于后执行
}公共无效onProviderDisabled(字符串提供商){}公共无效onProviderEnabled(字符串提供商){}公共无效onStatusChanged(字符串提供商,INT地位,捆绑演员){}

不要忘了事后删除位置更新。

My code putput always goes in else part. IT means {location} is null.

Any suggestions?

locManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
locManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,0,0, locationListener);  
location = locManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);

            if(location != null)                                
            {
        double latitude = location.getLatitude();
        double longitude = location.getLongitude();

            }  else {
                // 
            }
.....
.....
....

解决方案

If locManager.getLastKnownLocation(LocationManager.GPS_PROVIDER) returns null then it means you have never been located.

If you want to get the new location, you should make you activity extend the LocationListener interface and implement the following.

public void onLocationChanged(Location location) {
    // Code to execute after being located
}

public void onProviderDisabled(String provider) {

}

public void onProviderEnabled(String provider) {

}

public void onStatusChanged(String provider, int status, Bundle extras) {

}

Don't forget to remove the location updates afterwards.

这篇关于用户未找到位置 - 经度和纬度的android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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