I got the below code from @DanS at this link how-to-display-a-map-still-image-file-with-a-moving-current-location
onCurrentPosition(Location current){
double hypotenuse = upperLeft.distanceTo(current);
double bearing = upperLeft.bearingTo(current);
double currentDistanceX = Math.cos(bearing) * hypotenuse;
// "percentage to mark the position"
double currentPixelX = (currentDistanceX / upperLeft.distanceTo(lowerRight) * Math.cos(upperLeft.bearingTo(lowerRight))) * mapWidth;
moveIndicatorX(currentPixelX);
}
Here are the values:
- current: 41.850033,-87.65005229999997
- upperLeft: 41.866514127810355,-87.6720142364502
- lowerRight: 41.83397145565242,-87.62824058532715
- mapWidth: 512 x 512 px
Here are the calculator online for Location, hypotenuse(Distance), bearing(Azimuths)
- convert LatLng to Location format(e.g. 41° 51′ 59.45″ N 87° 40′ 19.25″ W)
- compute distance & azimuths from the given Location
I got the results of:
- hypotenuse = 2581
- bearing = 135.21
- currentDistanceX = -2562
- currentPixelX = 311.9
Would like to ask you guys to:
- to confirm if my computed results are correct.
- on how to compute the currentPixelY (the another one point)?
By the way, I am planning to use that to compute the location of a given real life LatLng(current) against with my still image map which bonded the upperLeft and lowerRight corners of the still image into real life LatLng.
If you want to see the actual & expected output and want to easily understand the whole picture. Please refer to this link -> How to mark the current location into a still image map