From 8ef41d95a562ee15e24426c753a1290629382cab Mon Sep 17 00:00:00 2001 From: Greg Lonnon Date: Sat, 4 Feb 2012 05:46:08 -0700 Subject: [PATCH] strava map jagged fix - issue was the conversion of gps coord to string didn't have enough precision. Found all (most) of the gps coord to string conversions and used a constant to insure all conversions occur with the same precision. Signed-off-by: Greg Lonnon --- src/BingMap.cpp | 24 ++++++++++++------------ src/GoogleMapControl.cpp | 27 +++++++++++++++------------ src/StravaDialog.cpp | 9 +++++---- src/Units.h | 1 + 4 files changed, 33 insertions(+), 28 deletions(-) diff --git a/src/BingMap.cpp b/src/BingMap.cpp index 83115f5ee..4b45de1fb 100644 --- a/src/BingMap.cpp +++ b/src/BingMap.cpp @@ -240,7 +240,7 @@ void BingMap::createHtml() " webBridge.drawOverlays();\n" "}\n" - "\n").arg(minLat,0,'g',11).arg(minLon,0,'g',11).arg(maxLat,0,'g',11).arg(maxLon,0,'g',11); + "\n").arg(minLat,0,'g',GPS_COORD_TO_STRING).arg(minLon,0,'g',GPS_COORD_TO_STRING).arg(maxLat,0,'g',GPS_COORD_TO_STRING).arg(maxLon,0,'g',GPS_COORD_TO_STRING); // the main page is rather trivial currentPage += QString("\n" @@ -275,7 +275,7 @@ BingMap::drawShadedRoute() code = QString("{\nvar route = new Array();\n"); } else { if (rfp->lat || rfp->lon) - code += QString("route.push(new Microsoft.Maps.Location(%1,%2));\n").arg(rfp->lat,0,'g',11).arg(rfp->lon,0,'g',11); + code += QString("route.push(new Microsoft.Maps.Location(%1,%2));\n").arg(rfp->lat,0,'g',GPS_COORD_TO_STRING).arg(rfp->lon,0,'g',GPS_COORD_TO_STRING); } // running total of time @@ -354,7 +354,7 @@ BingMap::createMarkers() "var pushpinOptions = { icon: 'qrc:images/maps/loop.png', height: 37, width: 32 };" "var pushpin = new Microsoft.Maps.Pushpin(latlng, pushpinOptions);" "map.entities.push(pushpin); }" - ).arg(points[0]->lat,0,'g',11).arg(points[0]->lon,0,'g',11); + ).arg(points[0]->lat,0,'g',GPS_COORD_TO_STRING).arg(points[0]->lon,0,'g',GPS_COORD_TO_STRING); view->page()->mainFrame()->evaluateJavaScript(code); @@ -364,14 +364,14 @@ BingMap::createMarkers() "var pushpinOptions = { icon: 'qrc:images/maps/cycling.png', height: 37, width: 32 };" "var pushpin = new Microsoft.Maps.Pushpin(latlng, pushpinOptions);" "map.entities.push(pushpin); }" - ).arg(points[0]->lat,0,'g',11).arg(points[0]->lon,0,'g',11); + ).arg(points[0]->lat,0,'g',GPS_COORD_TO_STRING).arg(points[0]->lon,0,'g',GPS_COORD_TO_STRING); view->page()->mainFrame()->evaluateJavaScript(code); code = QString("{ var latlng = new Microsoft.Maps.Location(%1,%2); " "var pushpinOptions = { icon: 'qrc:images/maps/finish.png', height: 37, width: 32 };" "var pushpin = new Microsoft.Maps.Pushpin(latlng, pushpinOptions);" "map.entities.push(pushpin); }" - ).arg(points[points.count()-1]->lat,0,'g',11).arg(points[points.count()-1]->lon,0,'g',11); + ).arg(points[points.count()-1]->lat,0,'g',GPS_COORD_TO_STRING).arg(points[points.count()-1]->lon,0,'g',GPS_COORD_TO_STRING); view->page()->mainFrame()->evaluateJavaScript(code); } @@ -416,7 +416,7 @@ BingMap::createMarkers() "var pushpinOptions = { icon: 'qrc:images/maps/cycling_feed.png', height: 37, width: 32 };" "var pushpin = new Microsoft.Maps.Pushpin(latlng, pushpinOptions);" "map.entities.push(pushpin); }" - ).arg(rfp->lat,0,'g',11).arg(rfp->lon,0,'g',11); + ).arg(rfp->lat,0,'g',GPS_COORD_TO_STRING).arg(rfp->lon,0,'g',GPS_COORD_TO_STRING); view->page()->mainFrame()->evaluateJavaScript(code); stoptime=0; } @@ -441,8 +441,8 @@ BingMap::createMarkers() "pushpin.cm1001_er_etr.dom.setAttribute('title', '%3');\n" "pushpinClick= Microsoft.Maps.Events.addHandler(pushpin, 'click', function(event) { webBridge.toggleInterval(%4); });\n" " }") - .arg(myRideItem->ride()->dataPoints()[offset]->lat,0,'g',11) - .arg(myRideItem->ride()->dataPoints()[offset]->lon,0,'g',11) + .arg(myRideItem->ride()->dataPoints()[offset]->lat,0,'g',GPS_COORD_TO_STRING) + .arg(myRideItem->ride()->dataPoints()[offset]->lon,0,'g',GPS_COORD_TO_STRING) .arg(x.name) .arg(interval); @@ -489,10 +489,10 @@ void BingMap::zoomInterval(IntervalItem *which) " new Microsoft.Maps.Location(%1,%2), " " new Microsoft.Maps.Location(%3,%4));\n" " map.setView( { bounds: viewBounds });\n }") - .arg(minLat,0,'g',11) - .arg(minLon,0,'g',11) - .arg(maxLat,0,'g',11) - .arg(maxLon,0,'g',11); + .arg(minLat,0,'g',GPS_COORD_TO_STRING) + .arg(minLon,0,'g',GPS_COORD_TO_STRING) + .arg(maxLat,0,'g',GPS_COORD_TO_STRING) + .arg(maxLon,0,'g',GPS_COORD_TO_STRING); view->page()->mainFrame()->evaluateJavaScript(code); } diff --git a/src/GoogleMapControl.cpp b/src/GoogleMapControl.cpp index e04745547..33883edfa 100644 --- a/src/GoogleMapControl.cpp +++ b/src/GoogleMapControl.cpp @@ -243,7 +243,10 @@ void GoogleMapControl::createHtml() " webBridge.drawOverlays();\n" "}\n" - "\n").arg(minLat,0,'g',11).arg(minLon,0,'g',11).arg(maxLat,0,'g',11).arg(maxLon,0,'g',11); + "\n").arg(minLat,0,'g',GPS_COORD_TO_STRING). + arg(minLon,0,'g',GPS_COORD_TO_STRING). + arg(maxLat,0,'g',GPS_COORD_TO_STRING). + arg(maxLon,0,'g',GPS_COORD_TO_STRING); // the main page is rather trivial currentPage += QString("\n" @@ -280,7 +283,7 @@ GoogleMapControl::drawShadedRoute() " path = polyline.getPath();\n"); } else { if (rfp->lat || rfp->lon) - code += QString("path.push(new google.maps.LatLng(%1,%2));\n").arg(rfp->lat,0,'g',11).arg(rfp->lon,0,'g',11); + code += QString("path.push(new google.maps.LatLng(%1,%2));\n").arg(rfp->lat,0,'g',GPS_COORD_TO_STRING).arg(rfp->lon,0,'g',GPS_COORD_TO_STRING); } // running total of time @@ -355,20 +358,20 @@ GoogleMapControl::createMarkers() code = QString("{ var latlng = new google.maps.LatLng(%1,%2);" "var image = new google.maps.MarkerImage('qrc:images/maps/loop.png');" "var marker = new google.maps.Marker({ icon: image, animation: google.maps.Animation.DROP, position: latlng });" - "marker.setMap(map); }").arg(points[0]->lat,0,'g',11).arg(points[0]->lon,0,'g',11); + "marker.setMap(map); }").arg(points[0]->lat,0,'g',GPS_COORD_TO_STRING).arg(points[0]->lon,0,'g',GPS_COORD_TO_STRING); view->page()->mainFrame()->evaluateJavaScript(code); } else { // start / finish markers code = QString("{ var latlng = new google.maps.LatLng(%1,%2);" "var image = new google.maps.MarkerImage('qrc:images/maps/cycling.png');" "var marker = new google.maps.Marker({ icon: image, animation: google.maps.Animation.DROP, position: latlng });" - "marker.setMap(map); }").arg(points[0]->lat,0,'g',11).arg(points[0]->lon,0,'g',11); + "marker.setMap(map); }").arg(points[0]->lat,0,'g',GPS_COORD_TO_STRING).arg(points[0]->lon,0,'g',GPS_COORD_TO_STRING); view->page()->mainFrame()->evaluateJavaScript(code); code = QString("{ var latlng = new google.maps.LatLng(%1,%2);" "var image = new google.maps.MarkerImage('qrc:images/maps/finish.png');" "var marker = new google.maps.Marker({ icon: image, animation: google.maps.Animation.DROP, position: latlng });" - "marker.setMap(map); }").arg(points[points.count()-1]->lat,0,'g',11).arg(points[points.count()-1]->lon,0,'g',11); + "marker.setMap(map); }").arg(points[points.count()-1]->lat,0,'g',GPS_COORD_TO_STRING).arg(points[points.count()-1]->lon,0,'g',GPS_COORD_TO_STRING); view->page()->mainFrame()->evaluateJavaScript(code); } @@ -414,7 +417,7 @@ GoogleMapControl::createMarkers() "var image = new google.maps.MarkerImage('qrc:images/maps/cycling_feed.png');" "var marker = new google.maps.Marker({ icon: image, animation: google.maps.Animation.DROP, position: latlng });" "marker.setMap(map);" - "}").arg(rfp->lat,0,'g',11).arg(rfp->lon,0,'g',11); + "}").arg(rfp->lat,0,'g',GPS_COORD_TO_STRING).arg(rfp->lon,0,'g',GPS_COORD_TO_STRING); view->page()->mainFrame()->evaluateJavaScript(code); stoptime=0; } @@ -440,8 +443,8 @@ GoogleMapControl::createMarkers() " markerList.push(marker);" // keep track of those suckers " google.maps.event.addListener(marker, 'click', function(event) { webBridge.toggleInterval(%4); });" "}") - .arg(myRideItem->ride()->dataPoints()[offset]->lat,0,'g',11) - .arg(myRideItem->ride()->dataPoints()[offset]->lon,0,'g',11) + .arg(myRideItem->ride()->dataPoints()[offset]->lat,0,'g',GPS_COORD_TO_STRING) + .arg(myRideItem->ride()->dataPoints()[offset]->lon,0,'g',GPS_COORD_TO_STRING) .arg(x.name) .arg(interval); view->page()->mainFrame()->evaluateJavaScript(code); @@ -486,10 +489,10 @@ void GoogleMapControl::zoomInterval(IntervalItem *which) "var northeast = new google.maps.LatLng(%3, %4);\n" "var bounds = new google.maps.LatLngBounds(southwest, northeast);\n" "map.fitBounds(bounds);\n }") - .arg(minLat,0,'g',11) - .arg(minLon,0,'g',11) - .arg(maxLat,0,'g',11) - .arg(maxLon,0,'g',11); + .arg(minLat,0,'g',GPS_COORD_TO_STRING) + .arg(minLon,0,'g',GPS_COORD_TO_STRING) + .arg(maxLat,0,'g',GPS_COORD_TO_STRING) + .arg(maxLon,0,'g',GPS_COORD_TO_STRING); view->page()->mainFrame()->evaluateJavaScript(code); } diff --git a/src/StravaDialog.cpp b/src/StravaDialog.cpp index b9f19c18c..0635c66ba 100644 --- a/src/StravaDialog.cpp +++ b/src/StravaDialog.cpp @@ -23,6 +23,7 @@ #include #include #include "TimeUtils.h" +#include "Units.h" // acccess to metrics #include "MetricAggregator.h" @@ -296,7 +297,7 @@ StravaDialog::requestUpload() connect(&networkMgr, SIGNAL(finished(QNetworkReply*)), this, SLOT(requestUploadFinished(QNetworkReply*))); connect(&networkMgr, SIGNAL(finished(QNetworkReply *)), &eventLoop, SLOT(quit())); - QByteArray out; + QString out; QVector vectorPoints = ride->ride()->dataPoints(); int totalSize = vectorPoints.size(); @@ -318,9 +319,9 @@ StravaDialog::requestUpload() out += "[\""; out += rideDateTime.toString("yyyy-MM-ddThh:mm:ss-0600"); out += "\","; - out += QString("%1").arg(point->lat); + out += QString("%1").arg(point->lat,0,'f',GPS_COORD_TO_STRING); out += ","; - out += QString("%1").arg(point->lon); + out += QString("%1").arg(point->lon,0,'f',GPS_COORD_TO_STRING); out += ","; out += QString("%1").arg(point->alt); out += ","; @@ -346,7 +347,7 @@ StravaDialog::requestUpload() progressBar->setValue(40); progressLabel->setText(tr("Upload ride... Sending")); - networkMgr.post( request, out); + networkMgr.post( request, out.toAscii()); eventLoop.exec(); } diff --git a/src/Units.h b/src/Units.h index 449a3a6db..f2cd71931 100644 --- a/src/Units.h +++ b/src/Units.h @@ -28,6 +28,7 @@ #define KG_PER_LB 0.45359237 #define FAHRENHEIT_PER_CENTIGRADE 1.8 #define FAHRENHEIT_ADD_CENTIGRADE 32 +#define GPS_COORD_TO_STRING 8 #endif // _GC_Units_h