0

我正在尝试使用以下代码获取用户当前的纬度/经度:

LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE); 
Location location = (Location) lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);

double longitude = location.getLongitude();
double latitude = location.getLatitude();

我不断收到错误,即方法 getLatitude()/getLongitude() 未定义类型Location

我该如何解决这个问题?提前致谢。

4

1 回答 1

1
import android.location.Location;
import android.location.LocationManager; 

添加这两个导入,或者如果您使用的是 eclipse,只需按 ctrl+shift+O 并尝试

于 2012-04-15T03:12:09.843 回答