2011-12-27 8 views
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を拡張するクラスを作成しました。私は他の抽象クラスも実装しています。私はこのコードを使って都市名を得ることができました。今は動作しません。ジオコーダを使用して地名を見つける際の問題

このコードに間違いがありますか?

+1

役立つかもしれない....これを試してみてください?エラー?スタックトレース? – jagsler

+0

私はNULLポインターエラーを取得しています。私はyを知りません。私は緯度も長めでもありません。 – Jeet

+0

どの行に..? – jagsler

答えて

0

が動作していない何

String add1 = ""; 
Geocoder geoCoder = new Geocoder(context, Locale.getDefault()); 

geoLatitude = p.getLatitudeE6()/1E6; 
geoLongitude = p.getLongitudeE6()/1E6; 

try { 
    List<Address> addresses = geoCoder.getFromLocation(p.getLatitudeE6()/1E6, p.getLongitudeE6()/1E6, 1); 

    if(addresses.size() > 0) { 
     for(int i=0; i<addresses.get(0).getMaxAddressLineIndex(); i++) { 
      add1 += addresses.get(0).getAddressLine(i) + "\n"; 
     }    
    } 
}catch(IOException ioe) { 
    ioe.printStackTrace(); 
} 
関連する問題