我遵循這個問題(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文檔,「該結果是最好的猜測,並不保證是有意義的或正確的。「 –