2014-06-10 57 views

回答

2

可以从这样一个地址检索位置:

public GeoPoint getLocationFromAddress(String strAddress) { 
    Geocoder coder = new Geocoder(this); 
    List<Address> address = new ArrayList<Address>(); 

    try { 
     address = coder.getFromLocationName(strAddress,5); 
     if (address == null) { 
      return null; 
     } 
     Address location = address.get(0); 
     location.getLatitude(); 
     location.getLongitude(); 

     GeoPoint p1 = new GeoPoint((int) (location.getLatitude() * 1E6), 
          (int) (location.getLongitude() * 1E6)); 

     return p1; 
    } catch (Exception e) {} 

    return null; 
} 

而对于距离使用distanceBetween

相关问题