Android 获取纬度、经度和插入url

Android 获取纬度、经度和插入url,android,url,latitude-longitude,Android,Url,Latitude Longitude,我得到了纬度和经度的使用位置。 并保存在 private double mLatitude; private double mLongitude;. mLatitude = location.getLatitude(); mLongitude =location.getLongitude(); locationMg =(LocationManager)getSystemService(Context.LOCATION_SERVICE); Criteria criteria =

我得到了纬度和经度的使用位置。 并保存在

private double mLatitude;

private double mLongitude;.

mLatitude = location.getLatitude();

mLongitude =location.getLongitude();

locationMg =(LocationManager)getSystemService(Context.LOCATION_SERVICE);

    Criteria criteria = new Criteria();
    criteria.setAccuracy(Criteria.ACCURACY_COARSE);
    criteria.setPowerRequirement(Criteria.POWER_LOW);
    criteria.setAltitudeRequired(false);
    criteria.setBearingRequired(false);
    criteria.setSpeedRequired(false);
    criteria.setCostAllowed(true);

    String bestProvider = locationMg.getBestProvider(criteria, true);
    Location location = locationMg.getLastKnownLocation(bestProvider);

    if(location != null){
        Toast.makeText(this,"Latitude" +location.getLatitude()+"\n"+"Longitude"+location.getLongitude(), 0).show();
         mLatitude = location.getLatitude();
         mLongitude = location.getLongitude();


    }

运行此代码后,我看到了LogCat。 然而,经度和纬度的值为0.0。 为什么? 是因为字符串类型url?????????????? 而纬度和经度只能是双精度。 是否更改url

救命啊。
我不知道该怎么办。

可能在知道位置后您没有定义url。把ir放在这里:

if(location != null){
        Toast.makeText(this,"Latitude" +location.getLatitude()+"\n"+"Longitude"+location.getLongitude(), 0).show();
         mLatitude = location.getLatitude();
         mLongitude = location.getLongitude();
         url ="http://api.openweathermap.org/data/2.5/weather?lat="+mLatitude+"&lon="+mLongitude+"&mode=xml";    
    }
如果提供程序当前已禁用,则从getLastKnownLocation()返回null

检查位置对象是否为空


使用
requestLocationUpdates(长时间、浮动距离、标准、挂起事件意图)注册位置更新

您确定有有效的位置吗?如何获取位置对象?是否使用emulator进行测试?@keerthanamurugesan是对的,在真实设备上测试…@keerthanamurugesan无模拟器,谷歌phone@SteveBenett添加代码!
if(location != null){
        Toast.makeText(this,"Latitude" +location.getLatitude()+"\n"+"Longitude"+location.getLongitude(), 0).show();
         mLatitude = location.getLatitude();
         mLongitude = location.getLongitude();
         url ="http://api.openweathermap.org/data/2.5/weather?lat="+mLatitude+"&lon="+mLongitude+"&mode=xml";    
    }