2012-02-19 10 views
1

私は現在位置を取得するために次のコードを書いています。私は別の緯度と経度でエミュレータでテストしています。しかし、実際の場所では緯度と経度を変換できません。逆ジオコーディングは動作しません

  public class LocationFindingActivity extends Activity { 
/** Called when the activity is first created. */ 

EditText et; 
LocationManager locationManager; 
String provider; 
LocationListener locationListener; 
Location currentLocation; 
String addressString=""; 
String longlattString=""; 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 

    et=(EditText)findViewById(R.id.locationTXT); 

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

    Criteria criteria = new Criteria(); 
    criteria.setAccuracy(Criteria.ACCURACY_FINE); 
    criteria.setAltitudeRequired(false); 
    criteria.setBearingRequired(false); 
    criteria.setCostAllowed(true); 
    criteria.setPowerRequirement(Criteria.POWER_LOW); 
    provider = locationManager.getBestProvider(criteria, true); 
    currentLocation=locationManager.getLastKnownLocation(provider); 


    et.setText(addressString); 
    locationListener =new LocationListener() { 

     @Override 
     public void onStatusChanged(String arg0, int arg1, Bundle arg2) { 
      // TODO Auto-generated method stub 

     } 

     @Override 
     public void onProviderEnabled(String arg0) { 
      // TODO Auto-generated method stub 

     } 

     @Override 
     public void onProviderDisabled(String arg0) { 
      // TODO Auto-generated method stub 

     } 

     @Override 
     public void onLocationChanged(Location arg0) { 
      // TODO Auto-generated method stub 
      updateWithNewLocation(currentLocation); 

     } 
    }; 
    updateWithNewLocation(currentLocation); 
    locationManager.requestLocationUpdates(provider, 2000, 10,locationListener) 

} 



private void updateWithNewLocation(Location location) { 




    if (location != null) 
    { 
     double lat = location.getLatitude(); 
     double lng = location.getLongitude(); 
     longlattstring="Lattitude :"+lat+"Longitude :"+lng; 


    Geocoder gc = new Geocoder(this, Locale.getDefault()); 

    try 
    { 
      List<Address> addresses = gc.getFromLocation(lat, lng, 1); 
      StringBuilder sb = new StringBuilder(); 
      //Toast.makeText(this, "Problem1", 2000).show(); 
      if (addresses.size() > 0) 
      { 
        Address address = addresses.get(0); 
        for (int i = 0; i < address.getMaxAddressLineIndex(); i++) 
         sb.append(address.getAddressLine(i)).append("\n"); 
        sb.append(address.getLocality()).append("\n"); 
        Toast.makeText(this, "Problem2", 2000).show(); 
        sb.append(address.getPostalCode()).append("\n"); 
        sb.append(address.getCountryName()); 
      } 
      addressString = sb.toString(); 
    } 
    catch (IOException e) 
    { 
     Toast.makeText(this, "Problem Catch", 2000).show(); 
    } 
} 


    else 
    { 
     addressString = "No location found";  
    } 

    et.setText(addressString); 


} 

}

私は

リストアドレス= gc.getFromLocationこの行で問題を取得しています(緯度、LNG、1);

このステートメントは何も返しません。

+0

私は同じ問題を抱えていて、何がうまくいかなかったのか理解できませんでした。だから、YahooのWeb APIを使ってジオコードを逆転させた。 –

答えて

0

固定されていない既知のバグです。service not avavilableを参照してください。これはAPIレベル7エミュレータで動作することがわかります。

+0

私はまだ問題に直面しているAPIレベル15を使用しています。 –

+1

それはおそらくあまりにも壊れています。 APIレベル7エミュレータで試してみてください。私が知る限り、すべてのAPIレベルで実際のデバイスで動作するはずです。 – NickT

+0

は私のコードが正しいです。 –

関連する問題