Search in sources :

Example 1 with GeoParsedPoint

use of net.osmand.util.GeoPointParserUtil.GeoParsedPoint in project Osmand by osmandapp.

the class AudioVideoNotesPlugin method indexSingleFile.

public boolean indexSingleFile(File f) {
    boolean oldFileExist = recordingByFileName.containsKey(f.getName());
    if (oldFileExist) {
        return false;
    }
    Recording r = new Recording(f);
    String fileName = f.getName();
    String otherName = r.getOtherName(fileName);
    int i = otherName.indexOf('.');
    if (i > 0) {
        otherName = otherName.substring(0, i);
    }
    r.file = f;
    GeoParsedPoint geo = MapUtils.decodeShortLinkString(otherName);
    r.lat = geo.getLatitude();
    r.lon = geo.getLongitude();
    Float heading = app.getLocationProvider().getHeading();
    Location loc = app.getLocationProvider().getLastKnownLocation();
    if (lastTakingPhoto != null && lastTakingPhoto.getName().equals(f.getName())) {
        float rot = heading != null ? heading : 0;
        try {
            r.updatePhotoInformation(r.lat, r.lon, loc, rot == 0 ? Double.NaN : rot);
        } catch (IOException e) {
            log.error("Error updating EXIF information " + e.getMessage(), e);
        }
        lastTakingPhoto = null;
    }
    recordings.registerObject(r.lat, r.lon, r);
    Map<String, Recording> newMap = new LinkedHashMap<>(recordingByFileName);
    newMap.put(f.getName(), r);
    recordingByFileName = newMap;
    if (isRecording()) {
        AVActionType type = currentRecording.type;
        finishRecording();
        if (type != AVActionType.REC_AUDIO && (!AV_RECORDER_SPLIT.get() || type != AVActionType.REC_VIDEO)) {
            final Recording recordingForMenu = r;
            app.runInUIThread(new Runnable() {

                @Override
                public void run() {
                    updateContextMenu(recordingForMenu);
                }
            }, 200);
        }
    }
    return true;
}
Also used : IOException(java.io.IOException) GeoParsedPoint(net.osmand.util.GeoPointParserUtil.GeoParsedPoint) LinkedHashMap(java.util.LinkedHashMap) GeoParsedPoint(net.osmand.util.GeoPointParserUtil.GeoParsedPoint) Location(net.osmand.Location)

Example 2 with GeoParsedPoint

use of net.osmand.util.GeoPointParserUtil.GeoParsedPoint in project Osmand by osmandapp.

the class MapUtils method decodeShortLinkString.

public static GeoParsedPoint decodeShortLinkString(String s) {
    // convert old shortlink format to current one
    s = s.replaceAll("@", "~");
    int i = 0;
    long x = 0;
    long y = 0;
    int z = -8;
    for (i = 0; i < s.length(); i++) {
        int digit = -1;
        char c = s.charAt(i);
        for (int j = 0; j < intToBase64.length; j++) if (c == intToBase64[j]) {
            digit = j;
            break;
        }
        if (digit < 0)
            break;
        if (digit < 0)
            break;
        // distribute 6 bits into x and y
        x <<= 3;
        y <<= 3;
        for (int j = 2; j >= 0; j--) {
            x |= ((digit & (1 << (j + j + 1))) == 0 ? 0 : (1 << j));
            y |= ((digit & (1 << (j + j))) == 0 ? 0 : (1 << j));
        }
        z += 3;
    }
    double lon = x * Math.pow(2, 2 - 3 * i) * 90. - 180;
    double lat = y * Math.pow(2, 2 - 3 * i) * 45. - 90;
    // adjust z
    if (i < s.length() && s.charAt(i) == '-') {
        z -= 2;
        if (i + 1 < s.length() && s.charAt(i + 1) == '-')
            z++;
    }
    return new GeoParsedPoint(lat, lon, z);
}
Also used : GeoParsedPoint(net.osmand.util.GeoPointParserUtil.GeoParsedPoint) GeoParsedPoint(net.osmand.util.GeoPointParserUtil.GeoParsedPoint) QuadPoint(net.osmand.data.QuadPoint)

Aggregations

GeoParsedPoint (net.osmand.util.GeoPointParserUtil.GeoParsedPoint)2 IOException (java.io.IOException)1 LinkedHashMap (java.util.LinkedHashMap)1 Location (net.osmand.Location)1 QuadPoint (net.osmand.data.QuadPoint)1