从GeoPoint变量中提取纬度和经度

时间:2014-10-22 15:17:10

标签: android latitude-longitude geopoints

Guyz我需要将用户当前位置作为纬度和经度,所以我定义了GeoPoint getLocationFromAddress(String strAddress),它将steAddress作为字符串addres的参数,然后将p1作为geopoint变量返回。现在我的问题是应该怎么做我从中单独提取纬度和经度,以便我可以在google地址api中使用请求URL。我在logcat中打印了该p1变量的值192508911,731430546。 下面是我的呼叫功能:

   GeoPoint lnglat=getLocationFromAddress(keyword);
   System.out.println(lnglat);
   Log.d("Location Point",lnglat.toString() ); 

以下是返回功能:

    public GeoPoint getLocationFromAddress(String strAddress){

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

    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;
    }
    catch(Exception e){
    e.printStackTrace();
    }
    return p1;
   }

1 个答案:

答案 0 :(得分:0)

GeoPoint类有特定的方法:

double lat = lnglat.getLatitude();

double lon = lnglat.getLongitude();

https://developer.mapquest.com/content/mobile/android/documentation/api/com/mapquest/android/maps/GeoPoint.html#getLatitude()