使用 java API 进行地理编码
Geocoding with java API
我正在使用 Nominatim java api 为 nomitim 获取给定地址的经度和纬度属性:https://github.com/AtlisInc/Nominatim-API。对于每个不同的输入经度和纬度输出是 same.For 纬度 = 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());
}
}
}
我没有使用 address.setCity(city);
,而是使用了 address.setCountry(city)
。对于每个指代地址的输入,您都可以使用 setCountry.It returns 真实经度和纬度 values.I 不明白为什么只有 setCountry 有效,但确实有效。
我正在使用 Nominatim java api 为 nomitim 获取给定地址的经度和纬度属性:https://github.com/AtlisInc/Nominatim-API。对于每个不同的输入经度和纬度输出是 same.For 纬度 = 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());
}
}
}
我没有使用 address.setCity(city);
,而是使用了 address.setCountry(city)
。对于每个指代地址的输入,您都可以使用 setCountry.It returns 真实经度和纬度 values.I 不明白为什么只有 setCountry 有效,但确实有效。