Search in sources :

Example 6 with GeoPoint

use of org.oscim.core.GeoPoint in project PocketMaps by junjunguo.

the class MyUtility method convertCoordingate.

/**
 * with or with out , in middle
 * <p>
 * <li>latitude, longitude</li> <li>latitude longitude</li>
 *
 * @param degrees
 * @return null if there is an error
 */
public static GeoPoint convertCoordingate(String degrees) {
    String[] lalo = new String[2];
    if (degrees.contains(",")) {
        lalo = degrees.split(",");
    } else {
        int n = degrees.indexOf("N");
        int ns = degrees.indexOf("n");
        int s = degrees.indexOf("S");
        int ss = degrees.indexOf("s");
        if (n > 0) {
            lalo[0] = degrees.substring(0, n + 1);
            lalo[1] = degrees.substring(n + 1);
        } else if (ns > 0) {
            lalo[0] = degrees.substring(0, ns + 1);
            lalo[1] = degrees.substring(ns + 1);
        } else if (s > 0) {
            lalo[0] = degrees.substring(0, s + 1);
            lalo[1] = degrees.substring(s + 1);
        } else if (ss > 0) {
            lalo[0] = degrees.substring(0, ss + 1);
            lalo[1] = degrees.substring(ss + 1);
        }
    }
    double latitude = toDecimal(lalo[0]);
    double logitude = toDecimal(lalo[1]);
    System.out.println("La: " + latitude + "\nLo: " + logitude);
    if (String.valueOf(latitude).length() == 1 || String.valueOf(logitude).length() == 1) {
        return null;
    }
    return new GeoPoint(latitude, logitude);
}
Also used : GeoPoint(org.oscim.core.GeoPoint) GeoPoint(org.oscim.core.GeoPoint)

Example 7 with GeoPoint

use of org.oscim.core.GeoPoint in project PocketMaps by junjunguo.

the class Variable method loadVariables.

/**
 * run when app open at run time
 * <p/>
 * load variables from saved file
 *
 * @return true if load succeed, false if nothing to load or load fail
 */
public boolean loadVariables() {
    String file = readFile();
    if (file == null) {
        return false;
    }
    JSONObject jo;
    try {
        jo = new JSONObject(file);
        setTravelMode(jo.getString("travelMode"));
        setWeighting(jo.getString("weighting"));
        setRoutingAlgorithms(jo.getString("routingAlgorithms"));
        setDirectionsON(jo.getBoolean("directionsON"));
        setAdvancedSetting(jo.getBoolean("advancedSetting"));
        setZoomLevelMax(jo.getInt("zoomLevelMax"));
        setZoomLevelMin(jo.getInt("zoomLevelMin"));
        setLastZoomLevel(jo.getInt("lastZoomLevel"));
        double la = jo.getDouble("latitude");
        double lo = jo.getDouble("longitude");
        if (la != 0 && lo != 0) {
            setLastLocation(new GeoPoint(la, lo));
        }
        String coun = jo.getString("country");
        if (coun != "") {
            setCountry(jo.getString("country"));
        }
        File mapsFolderAbsPath = new File(jo.getString("mapsFolderAbsPath"));
        if (mapsFolderAbsPath.exists()) {
            setBaseFolder(mapsFolderAbsPath.getParentFile().getParent());
        }
        setSportCategoryIndex(jo.getInt("sportCategoryIndex"));
    } catch (JSONException e) {
        e.printStackTrace();
        return false;
    }
    return true;
}
Also used : GeoPoint(org.oscim.core.GeoPoint) JSONObject(org.json.JSONObject) JSONException(org.json.JSONException) File(java.io.File)

Example 8 with GeoPoint

use of org.oscim.core.GeoPoint in project PocketMaps by junjunguo.

the class NaviEngine method setNavigating.

public void setNavigating(Activity activity, boolean active) {
    this.active = active;
    if (active && lightSensor == null) {
        lightSensor = new LightSensor(activity);
    } else if ((!active) && lightSensor != null) {
        lightSensor.cleanup(activity);
        lightSensor = null;
    }
    if (naviVoice == null) {
        naviVoice = new NaviVoice(activity.getApplicationContext());
    }
    if (active == false) {
        MapHandler.getMapHandler().setCustomPointIcon(R.drawable.ic_my_location_dark_24dp);
        if (pos != null) {
            GeoPoint curPos = new GeoPoint(pos.getLatitude(), pos.getLongitude());
            MapHandler.getMapHandler().centerPointOnMap(curPos, BEST_NAVI_ZOOM, 0, 0);
        }
        NaviDebugSimulator.getSimu().setSimuRun(false);
        return;
    }
    MapHandler.getMapHandler().setCustomPointIcon(R.drawable.ic_navigation_black_24dp);
    naviVoiceSpoken = false;
    uiJob = UiJob.Nothing;
    initFields(activity);
    instructions = Navigator.getNavigator().getGhResponse().getInstructions();
    resetNewInstruction();
    if (instructions.size() > 0) {
        startDebugSimulator(activity, false);
    }
}
Also used : GeoPoint(org.oscim.core.GeoPoint) LightSensor(com.junjunguo.pocketmaps.util.LightSensor)

Example 9 with GeoPoint

use of org.oscim.core.GeoPoint in project PocketMaps by junjunguo.

the class NaviEngine method calculatePosition.

@WorkerThread
private NaviInstruction calculatePosition(GeoPoint curPos) {
    if (uiJob == UiJob.RecalcPath) {
        return null;
    }
    if (uiJob == UiJob.Finished) {
        return null;
    }
    nearestP.setBaseData(getNearestPoint(instructions.get(0), nearestP.arrPos, curPos));
    if (nearestP.arrPos > 0) {
        // Check dist to line (backward)
        double lat1 = instructions.get(0).getPoints().getLatitude(nearestP.arrPos);
        double lon1 = instructions.get(0).getPoints().getLongitude(nearestP.arrPos);
        double lat2 = instructions.get(0).getPoints().getLatitude(nearestP.arrPos - 1);
        double lon2 = instructions.get(0).getPoints().getLongitude(nearestP.arrPos - 1);
        double lDist = GeoMath.distToLineSegment(curPos.getLatitude(), curPos.getLongitude(), lat1, lon1, lat2, lon2);
        if (lDist < nearestP.distance) {
            nearestP.distance = lDist;
            nearestP.status = PointPosData.Status.CurPosIsBackward;
        }
    }
    if (nearestP.arrPos < instructions.get(0).getPoints().size() - 1) {
        // Check dist to line (forward)
        double lat1 = instructions.get(0).getPoints().getLatitude(nearestP.arrPos);
        double lon1 = instructions.get(0).getPoints().getLongitude(nearestP.arrPos);
        double lat2 = instructions.get(0).getPoints().getLatitude(nearestP.arrPos + 1);
        double lon2 = instructions.get(0).getPoints().getLongitude(nearestP.arrPos + 1);
        double lDist = GeoMath.distToLineSegment(curPos.getLatitude(), curPos.getLongitude(), lat1, lon1, lat2, lon2);
        if (lDist < nearestP.distance) {
            nearestP.distance = lDist;
            nearestP.status = PointPosData.Status.CurPosIsForward;
        }
    } else if (nearestP.arrPos == instructions.get(0).getPoints().size() - 1 && instructions.size() > 1) {
        if (instructions.get(1).getPoints().size() > 0) {
            // Check dist to line (forward to next instruction)
            double lat1 = instructions.get(0).getPoints().getLatitude(nearestP.arrPos);
            double lon1 = instructions.get(0).getPoints().getLongitude(nearestP.arrPos);
            double lat2 = instructions.get(1).getPoints().getLatitude(0);
            double lon2 = instructions.get(1).getPoints().getLongitude(0);
            double lDist = GeoMath.distToLineSegment(curPos.getLatitude(), curPos.getLongitude(), lat1, lon1, lat2, lon2);
            if (lDist < nearestP.distance) {
                nearestP.distance = lDist;
                nearestP.status = PointPosData.Status.CurPosIsForward;
            }
        }
        if (instructions.get(1).getPoints().size() > 1) {
            // Check dist to line (forward next instruction p1+p2)
            double lat1 = instructions.get(1).getPoints().getLatitude(0);
            double lon1 = instructions.get(1).getPoints().getLongitude(0);
            double lat2 = instructions.get(1).getPoints().getLatitude(1);
            double lon2 = instructions.get(1).getPoints().getLongitude(1);
            double lDist = GeoMath.distToLineSegment(curPos.getLatitude(), curPos.getLongitude(), lat1, lon1, lat2, lon2);
            if (lDist < nearestP.distance) {
                nearestP.distance = lDist;
                nearestP.status = PointPosData.Status.CurPosIsForwardNext;
            }
        }
    }
    if (nearestP.isForward()) {
        log("Reset bearing with calculatePosition()");
        nearestP.resetDirectionOk();
    }
    if (!nearestP.isDistanceOk()) {
        Instruction nearestNext = instructions.find(curPos.getLatitude(), curPos.getLongitude(), MAX_WAY_TOLERANCE_METER);
        if (nearestNext == null) {
            GeoPoint closestP = findClosestStreet(curPos);
            nearestNext = instructions.find(closestP.getLatitude(), closestP.getLongitude(), MAX_WAY_TOLERANCE_METER);
        }
        if (nearestNext == null) {
            uiJob = UiJob.RecalcPath;
            recalcFrom = curPos;
            Instruction lastInstruction = instructions.get(instructions.size() - 1);
            int lastPoint = lastInstruction.getPoints().size() - 1;
            double lastPointLat = lastInstruction.getPoints().getLat(lastPoint);
            double lastPointLon = lastInstruction.getPoints().getLon(lastPoint);
            recalcTo = new GeoPoint(lastPointLat, lastPointLon);
            log("NaviTask Start recalc !!!!!!");
            return null;
        } else {
            // Forward to nearest instruction.
            int deleteCounter = 0;
            Instruction lastDeleted = null;
            while (instructions.size() > 0 && !instructions.get(0).equals(nearestNext)) {
                deleteCounter++;
                lastDeleted = instructions.remove(0);
            }
            if (lastDeleted != null) {
                // Because we need the current, and not the next Instruction
                instructions.add(0, lastDeleted);
                deleteCounter--;
            }
            if (deleteCounter == 0) {
                PointPosData newNearestP = getNearestPoint(instructions.get(0), 0, curPos);
                // TODO: Continue-Instruction with DirectionInfo: getContinueInstruction() ?
                log("NaviTask Start update far !!!!!!");
                return getUpdatedInstruction(curPos, newNearestP);
            }
            log("NaviTask Start update skip-mult-" + deleteCounter + " !!!!!!");
            return getNewInstruction();
        }
    } else if (nearestP.isForwardNext()) {
        instructions.remove(0);
        log("NaviTask Start skip-next !!!!!!");
        return getNewInstruction();
    } else {
        log("NaviTask Start update !!!!!!");
        return getUpdatedInstruction(curPos, nearestP);
    }
}
Also used : GeoPoint(org.oscim.core.GeoPoint) Instruction(com.graphhopper.util.Instruction) GeoPoint(org.oscim.core.GeoPoint) WorkerThread(android.support.annotation.WorkerThread)

Example 10 with GeoPoint

use of org.oscim.core.GeoPoint in project PocketMaps by junjunguo.

the class NaviEngine method countPartDistance.

/**
 * Counts the estimated rest-distance to next instruction. *
 */
private double countPartDistance(GeoPoint curPos, Instruction in, int nearestPointPos) {
    double partDistance = 0;
    double lastLat = curPos.getLatitude();
    double lastLon = curPos.getLongitude();
    for (int i = nearestPointPos + 1; i < in.getPoints().size(); i++) {
        double nextLat = in.getPoints().getLat(i);
        double nextLon = in.getPoints().getLon(i);
        partDistance += GeoMath.fastDistance(lastLat, lastLon, nextLat, nextLon);
        lastLat = nextLat;
        lastLon = nextLon;
    }
    partDistance = partDistance * GeoMath.METER_PER_DEGREE;
    return partDistance;
}
Also used : GeoPoint(org.oscim.core.GeoPoint)

Aggregations

GeoPoint (org.oscim.core.GeoPoint)25 File (java.io.File)5 RecyclerView (android.support.v7.widget.RecyclerView)4 View (android.view.View)4 AdapterView (android.widget.AdapterView)4 Location (android.location.Location)3 ViewGroup (android.view.ViewGroup)3 TextView (android.widget.TextView)3 Instruction (com.graphhopper.util.Instruction)3 ArrayList (java.util.ArrayList)3 MapView (org.oscim.android.MapView)3 MarkerSymbol (org.oscim.layers.marker.MarkerSymbol)3 Address (android.location.Address)2 MotionEvent (android.view.MotionEvent)2 IOException (java.io.IOException)2 BuildingLayer (org.oscim.layers.tile.buildings.BuildingLayer)2 VectorTileLayer (org.oscim.layers.tile.vector.VectorTileLayer)2 LabelLayer (org.oscim.layers.tile.vector.labeling.LabelLayer)2 MapFileTileSource (org.oscim.tiling.source.mapfile.MapFileTileSource)2 Intent (android.content.Intent)1