use of de.janrufmonitor.util.math.Point in project janrufmonitor by tbrandt77.
the class GeoDistance method getDistance.
private String getDistance(double lng, double lat) {
// get current location
Point local = GeoCoder.getInstance().getLocalPosition();
if (local == null) {
if (PIMRuntime.getInstance().getConfigManagerFactory().getConfigManager().getProperty("service.GeoCoding", "local-geo-acc").length() > 0) {
local = new Point(Double.parseDouble(PIMRuntime.getInstance().getConfigManagerFactory().getConfigManager().getProperty("service.GeoCoding", "local-geo-lng")), Double.parseDouble(PIMRuntime.getInstance().getConfigManagerFactory().getConfigManager().getProperty("service.GeoCoding", "local-geo-lat")), Integer.parseInt(PIMRuntime.getInstance().getConfigManagerFactory().getConfigManager().getProperty("service.GeoCoding", "local-geo-acc")));
GeoCoder.getInstance().setLocalPosition(local);
} else {
String areacode = PIMRuntime.getInstance().getConfigManagerFactory().getConfigManager().getProperty(IJAMConst.GLOBAL_NAMESPACE, IJAMConst.GLOBAL_AREACODE);
if (areacode != null && areacode.length() > 0) {
IPhonenumber pn = PhonenumberAnalyzer.getInstance(PIMRuntime.getInstance()).toPhonenumber(areacode + "1234567890");
ICaller caller = Identifier.identifyDefault(PIMRuntime.getInstance(), pn);
if (caller != null) {
local = GeoCoder.getInstance().getCoordinates(caller.getAttributes());
if (local == null)
return "";
GeoCoder.getInstance().setLocalPosition(local);
} else {
return "";
}
} else {
return "";
}
}
}
StringBuffer km = new StringBuffer(10);
DecimalFormat df = new DecimalFormat("0.0");
km.append(df.format(Distance.calculateDistance(new Point(lng, lat), local)));
km.append(" km");
return km.toString();
}
Aggregations