Search in sources :

Example 6 with Point

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();
}
Also used : ICaller(de.janrufmonitor.framework.ICaller) DecimalFormat(java.text.DecimalFormat) Point(de.janrufmonitor.util.math.Point) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Aggregations

Point (de.janrufmonitor.util.math.Point)6 ICaller (de.janrufmonitor.framework.ICaller)4 IAttributeMap (de.janrufmonitor.framework.IAttributeMap)1 ICall (de.janrufmonitor.framework.ICall)1 ICallerList (de.janrufmonitor.framework.ICallerList)1 IPhonenumber (de.janrufmonitor.framework.IPhonenumber)1 IEventBroker (de.janrufmonitor.framework.event.IEventBroker)1 ICallManager (de.janrufmonitor.repository.ICallManager)1 IWriteCallRepository (de.janrufmonitor.repository.types.IWriteCallRepository)1 BufferedInputStream (java.io.BufferedInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 URLConnection (java.net.URLConnection)1 DecimalFormat (java.text.DecimalFormat)1 Iterator (java.util.Iterator)1 List (java.util.List)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1