【发布时间】: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