2013-07-23 200 views

回答

0

得到當前的經緯度使用:LocationManager

LocationManager locationmanager = (LocationManager) getSystemService(LOCATION_SERVICE); 
     Criteria cr = new Criteria(); 
     String provider = locationmanager.getBestProvider(cr, true); 
     Location location = locationmanager.getLastKnownLocation(provider); 
     if (location != null) { 
      double lat=location.getLatitude(); 
     double lng=location.getLongitude(); 
     } 

通當前的經緯度到下面的方法將返回您解決!

public List<Address> getAddress(double latitude, double longitude) { 
     List<Address> addresses = null; 
     try { 

      Geocoder geocoder; 

      geocoder = new Geocoder(youractivityname.this); 
      if (latitude != 0 || longitude != 0) { 
       addresses = geocoder.getFromLocation(latitude, longitude, 1); 

       //testing address below 

       String address = addresses.get(0).getAddressLine(0); 
       String city = addresses.get(0).getAddressLine(1); 
       String country = addresses.get(0).getAddressLine(2); 
       Log.d("TAG", "address = " + address + ", city =" + city 
         + ", country = " + country); 

      } 

     } catch (Exception e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
      // Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show(); 
     } 
     return addresses; 
    } 
+0

列表

和passangerHome.this是未知的。? –

+0

passangerHome.this = youractivityname.this –

+0

import java.util.List; –