如何通过Android中的地址位置获取经度和纬度

时间:2014-03-12 15:01:10

标签: android gps

我正在开发Android应用,其中我在编辑文本中占据目的地,我想要输入位置的纬度和经度。

示例:我现在输入了编辑文本pune我想要它的纬度和经度。

1 个答案:

答案 0 :(得分:0)

从这里开始:https://stackoverflow.com/a/3574792/2065418

   Geocoder coder = new Geocoder(this);
    List<Address> address;

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

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

         return p1;
    }

strAddress是包含地址的字符串。 address变量保存已转换的地址。