我正在为Nomitim使用Nominatim Java API,以获取给定地址https://github.com/AtlisInc/Nominatim-API的经度和纬度属性。对于每个不同的输入,经度和纬度的输出都相同。对于纬度= 51.3258094和对于经度= 11.3400106。我究竟做错了什么? 这是代码:
public class Geocoding(){
private volatile NominatimAPI nominatimAPI;//Use Volatile
public NominatimAPI getNominatimAPI(){
NominatimAPI result=nominatimAPI;
if(result==null){
synchronized (this){//Synchronize for thread safety
result=nominatimAPI;
if (result==null){
result=new NominatimAPI();
nominatimAPI=result;
}
}
}
return result;
}
private static void mymethod2() {
List<String> cities = Arrays.asList("Los Angeles","Berlin");
String endpointUrl = "https://nominatim.openstreetmap.org/";
MapPoint mapPoint;
Geocoding test=new Geocoding();
for (String city : cities) {
NominatimAPI nominatim = test.getNominatimAPI();
Address address = new Address();
address.setCity(city);
nominatim.initNominatimAPI(endpointUrl);
mapPoint = nominatim.getMapPointFromAddress(address, 18);
System.out.println(mapPoint.getLatitude()+","+mapPoint.getLongitude());
}
}
}
答案 0 :(得分:0)
我没有使用address.setCity(city);
,而是使用address.setCountry(city)
。对于每个引用nominatim地址的输入,您都可以使用setCountry。它返回的是真实的经度和纬度值。我不明白为什么只有setCountry可以,但是可以。