HI,
I´ve got a Latitude Longitude points series which I want to draw on a display of a watch. The problem is with projecting the Lat/Lng pairs into the pixels. I´ve got the bounding box of the track. So far I´ve been using this function which plots some tracks just fine, but a lot of them is squashed. Mainly those tracks that are bigger in width, than height. I´ve seen a lot of apps use this feature, but nowhere to find the proper formula to project the points.
function transformToPixels(lat, lon){
var westLongitude = boundingBox[1].toDegrees()[1];
var eastLongitude = boundingBox[0].toDegrees()[1];
var northLatitude = boundingBox[1].toDegrees()[0];
var southLatitude = boundingBox[0].toDegrees()[0];
var longitudeDiff = eastLongitude - westLongitude;
var latitudeDiff = northLatitude - southLatitude;
var xPixel = (((eastLongitude - lon) / (longitudeDiff).toDouble()) * DISPLAY_WIDTH).toNumber();
var yPixel = (((northLatitude - lat) / (latitudeDiff).toDouble()) * DISPLAY_HEIGHT).toNumber();
return [xPixel - 3, yPixel + 20]; //figured these numbers to somehow fit the space
}
Thanks for help.