-1

在此处输入图像描述我得到了经纬度使用位置。并保存在

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();


    }

private String url ="http://api.openweathermap.org/data/2.5/weather?lat="+mLatitude+"&lon="+mLongitude+"&mode=xml";

运行此代码后,我看到了 LogCat。但是,0.0的经纬度的值就出来了。为什么?是不是因为字符串类型的url????????????和纬度和经度应该只类型是双。换个网址?

帮助。我不知道该怎么办。

4

2 回答 2

0

文档 If the provider is currently disabled, null is returned from getLastKnownLocation()

检查位置对象是否为空。

使用注册位置更新requestLocationUpdates (long minTime, float minDistance, Criteria criteria, PendingIntent intent)

于 2013-08-06T08:13:09.570 回答
-1

知道位置后,您可能没有定义 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";    
    }
于 2013-08-06T07:59:53.120 回答