diff --git a/importPicture/src/osm/jp/gpx/ImportPicture.java b/importPicture/src/osm/jp/gpx/ImportPicture.java index e56c698..5c14a62 100644 --- a/importPicture/src/osm/jp/gpx/ImportPicture.java +++ b/importPicture/src/osm/jp/gpx/ImportPicture.java @@ -9,10 +9,10 @@ import java.util.Comparator; import java.util.Date; import java.util.GregorianCalendar; -import java.util.HashMap; import java.util.Iterator; import java.util.Set; import java.util.TimeZone; +import java.util.TreeMap; import java.util.logging.LogManager; import java.util.logging.Logger; @@ -200,7 +200,7 @@ */ - HashMap map = new HashMap<>(); + TreeMap map = new TreeMap<>(); Element trk = null; gpx = builder.parse(gpxFile).getFirstChild(); NodeList nodes = gpx.getChildNodes(); @@ -270,7 +270,7 @@ * @throws ImageReadException * @throws ImageWriteException */ - static void proc(File dir, long delta, long gpxStartTime, long gpxEndTime, HashMap map, boolean exifWrite, Node gpx) throws ParseException, ImageReadException, IOException, ImageWriteException { + static void proc(File dir, long delta, long gpxStartTime, long gpxEndTime, TreeMap map, boolean exifWrite, Node gpx) throws ParseException, ImageReadException, IOException, ImageWriteException { DecimalFormat yearFormatter = new DecimalFormat("0000"); DecimalFormat monthFormatter = new DecimalFormat("00"); DecimalFormat dayFormatter = new DecimalFormat("00"); @@ -462,7 +462,7 @@ * @param map * @throws ParseException */ - public static void trkptMap(Element trk, HashMap map) throws ParseException { + public static void trkptMap(Element trk, TreeMap map) throws ParseException { dfuk.setTimeZone(TimeZone.getTimeZone("GMT")); NodeList nodes1 = trk.getChildNodes(); @@ -510,8 +510,8 @@ * @param jptime * @throws ParseException */ - public static Element trkpt(HashMap map, Date jptime) throws ParseException { - Double R = 20000000 / Math.PI; // 地球の半径(m) + public static Element trkpt(TreeMap map, Date jptime) throws ParseException { + Double R = 20000000 / Math.PI; long sa = 2L * 3600000L; long jpt = jptime.getTime(); Element ret = null; @@ -572,20 +572,25 @@ break; } } - Double dLON = imaLON - maeLON; - Double dLAT = imaLAT - maeLAT; - Double r = Math.cos(Math.toRadians((imaLAT + maeLAT) * 2)) * R; + Double r = Math.cos(Math.toRadians((imaLAT + maeLAT) / 2)) * R; Double x = Math.toRadians(imaLON - maeLON) * r; Double y = Math.toRadians(imaLAT - maeLAT) * R; - double rad = Math.toDegrees(Math.atan(y / x)); + double rad = Math.toDegrees(Math.atan2(y, x)); - if (y < 0) { - rad = rad * -1; - if (x > 0) { - rad = rad + 90; + if (y >= 0) { + if (x >= 0) { + rad = 0 - (rad - 90); } else { - rad = rad - 90; + rad = 360 - (rad - 90); + } + } + else { + if (x >= 0) { + rad = 90 - rad; + } + else { + rad = 90 - rad; } } @@ -597,6 +602,15 @@ } magvar.setTextContent(str); ret.appendChild(magvar); + + Element speed = ret.getOwnerDocument().createElement("speed"); + str = Double.toString(Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2))); + iDot = str.indexOf('.'); + if (iDot > 0) { + str = str.substring(0, iDot); + } + speed.setTextContent(str); + ret.appendChild(speed); } } }