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