【问题标题】:How to get Latlng from Input name of location for Android如何从 Android 位置的输入名称中获取 Latlng
【发布时间】:2014-09-03 15:54:09
【问题描述】:

我想要一个示例代码,它可以让我们定位车牌,就像导航系统一样,按我们输入的名称搜索。从我们现在的位置到我们设定的目的地的位置。

【问题讨论】:

标签: android


【解决方案1】:

使用这个方法

 /**
 * Get list of address by latitude and longitude
 * @return null or List<Address>
 */
public List<Address> getGeocoderAddress(Context context)
{
    if (location != null)
    {
        Geocoder geocoder = new Geocoder(context, Locale.ENGLISH);
        try 
        {
            List<Address> addresses = geocoder.getFromLocation(latitude, longitude, 1);
            return addresses;
        } 
        catch (IOException e) 
        {
            //e.printStackTrace();
            Log.e("Error : Geocoder", "Impossible to connect to Geocoder", e);
        }
    }

    return null;
}

问候 行家

【讨论】:

    【解决方案2】:

    您可以使用以下方法-

    public String getLatLonByAddress(String addr) {
    
            Geocoder geoCoder = new Geocoder(this);
            List<Address> address = null;
    
            try {
                address = geoCoder.getFromLocationName(addr, 5);
            }
            catch (IOException e) {
                e.printStackTrace();
            }
            if (address == null) {
                return null;
            }
            Address location = address.get(0);
    
            return location.getLatitude() + " / " + location.getLongitude();
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-03-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多