0
lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0,0, this);
Location location=lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
geocoder = new Geocoder(this);
if(location!=null)
onLocationChanged(location);
public void onLocationChanged(Location location) {
try {
List<Address> addresses = geocoder.getFromLocation(location.getLatitude(),location.getLongitude(), 2); // <10>
for (Address address : addresses) {
tv.setText(address.getAddressLine(0));
}
}catch(Exception e){
}
这是我的示例代码。我创建了一个扩展Locationlistener的类,我也实现了其他的抽象类。我能够使用此代码获取城市名称。现在它不工作。使用地理编码器查找地名的问题
这段代码有没有错误?
什么是不工作?错误?堆栈跟踪? – jagsler 2011-12-27 13:20:42
我得到空指针错误。我不知道Ÿ我没有得到经纬度。 – Jeet 2011-12-27 13:23:15
在哪一行..? – jagsler 2011-12-27 13:23:59