【问题标题】:Extract Latitude and Longitude from GeoPoint variable从 GeoPoint 变量中提取纬度和经度
【发布时间】:2014-10-22 15:17:09
【问题描述】:

Guyz 我需要将用户当前位置作为纬度和经度,所以我定义了 GeoPoint getLocationFromAddress(String strAddress),它将 steAddress 作为参数,字符串地址然后返回 p1 作为地理点变量。现在我的问题是应该如何我从中分别提取纬度和经度,以便可以在 google places 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;
   }

【问题讨论】:

    标签: android latitude-longitude geopoints


    【解决方案1】:

    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()

    【讨论】:

    • 但现在的问题是它正在放置点'。'在第一个数字之后,例如 1.92508911、7.31430546,而正确的格式是 19.2508911、73.1430546。我怎样才能获得正确的格式?
    • 而且它也不接受双纬度 = lnglat.getLatitude();双 lon = lnglat.getLongitude();我需要把它写成 double lat = lnglat.getLatitudeE6();当我将代码编写为 double lat = lnglat.getLatitude();它说方法 getLatitude() 对于 GeoPoint 类型未定义。所以我需要更改为 double lat = lnglat.getLatitudeE6();双 lng = lnglat.getLongitudeE6();
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-04
    • 2012-04-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多