我遵循这个问题(How can I find the latitude and longitude from address?)并尝试获取地址的经度和纬度。我将这种方法称为“GeoPoint point = getLocationFromAddress(”colombo,sri lanka“);” 。但给零值。如何正确调用方法?当从地址找到经纬度时,如何给出地址?
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;
}
}
从API文档,“该结果是最好的猜测,并不保证是有意义的或正确的。“ –